SnapExternalFile Class Reference

This class represents a file that exists in the /media directory. More...

Inheritance diagram for SnapExternalFile:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 __construct ($version, $array="")
 Create a new SnapExternalFile attached to a version.
 copy ($newName="")
 Creates a copy of this file.
 create ($tmpFile, $originalName, $name="")
 Creates an actual file on the file system.
 delete ()
 Destroy this file.
 getArray ()
 Retrieves "serialized" representation of the file.
 getName ()
 Retrieves the real name of the file this object represents.
 getPath ()
 Retrieves path on the server where file is located.
 getURL ()
 Retrieves URL to file.
 load ($array)
 Loads file information from serialized array generated by getArray().
 setAcceptable ($fileTypes)
 For directories: sets which file types are allowed to be contained in the directory.
 unzip ($callIt)
 If this is a zipfile, unzips it into a new directory.
 update ($tmpFile, $originalName, $name="")
 Modifies existing file or changes its name.
 weedFiles ($directory= 'default')
 For directories: weeds out files that do not belong to list of acceptable file types.


Detailed Description

This class represents a file that exists in the /media directory.

There are several things we may want to do with it.


Constructor & Destructor Documentation

SnapExternalFile::__construct ( version,
array = "" 
)

Create a new SnapExternalFile attached to a version.

Parameters:
$version [SnapVersion]: version that this external file is associated with
$array [array]: array of information representing a file to be loaded (array comes from getArray())


Member Function Documentation

SnapExternalFile::copy ( newName = ""  ) 

Creates a copy of this file.

The copy can have a different name if given as the sole parameter, otherwise, the old name is used.

Parameters:
$newName [string]: optional new name for copy
Returns:
[SnapExternalFile]: external file object representing copy of this file

SnapExternalFile::create ( tmpFile,
originalName,
name = "" 
)

Creates an actual file on the file system.

Merely creating a SnapExternalFile object is not enough to create a file. You must either call load() to load in an existing file, or call create() to create a new file/directory.

Parameters:
$tmpFile [string]: path to source file to upload
$originalName [string]: basename of the file (as, e.g., uploaded by the user)
$name [string]: alternate name for the file to be stored for future use
Returns:
[boolean]: success or failure INSERT BRIEF DESCRIPTION HERE INSERT FULL DESCRIPTION HERE
Parameters:
$tmpFile [TYPE]: DESCRIPTION
$originalName [TYPE]: DESCRIPTION
$name [TYPE]: DESCRIPTION
Returns:
[TYPE]: RETURN DESCRIPTION

SnapExternalFile::delete (  ) 

Destroy this file.

Destroy the file on the filesystem.

Returns:
[boolean]: success or failure

SnapExternalFile::getArray (  ) 

Retrieves "serialized" representation of the file.

The array returned from here is to be treated as opaque. It can be stored in Snap content, to be used to initialize a SnapExternalFile object in the future.

Returns:
[array]: representation of the file

SnapExternalFile::getName (  ) 

Retrieves the real name of the file this object represents.

External files have a hashed named which is meaningless. The original name is stored so that it can be used later after it would otherwise be lost.

Returns:
[string]: original name

SnapExternalFile::getPath (  ) 

Retrieves path on the server where file is located.

Returns:
[string]: server path to file

SnapExternalFile::getURL (  ) 

Retrieves URL to file.

Returns:
[string]: URL to file

SnapExternalFile::load ( array  ) 

Loads file information from serialized array generated by getArray().

Parameters:
$array [array]: representation of the file
Returns:
[boolean]: success or failure

SnapExternalFile::setAcceptable ( fileTypes  ) 

For directories: sets which file types are allowed to be contained in the directory.

This is useful for zipfiles, where we want to filter out invalid files in the zip (see weedFiles())

Parameters:
$fileTypes [array]: list of file suffixes that are acceptable
Returns:
[boolean]: success or failure

SnapExternalFile::unzip ( callIt  ) 

If this is a zipfile, unzips it into a new directory.

The new directory is represented by a SnapExternalFile, which is returned from this method. The original zipfile is not deleted.

Returns:
[SnapExternalFile]: external file object representing directory containing contents of unzipped file

SnapExternalFile::update ( tmpFile,
originalName,
name = "" 
)

Modifies existing file or changes its name.

Updating does not create new files, it just changes information about an existing file or changes the file itself, in place.

Parameters:
$tmpFile [string]: path to source file, or empty string if the file is not to be modified
$originalName [string]: original name of file, if that is to be modified
$name [string]: no idea why we even need this...
Returns:
[boolean]: success or failure

SnapExternalFile::weedFiles ( directory = 'default'  ) 

For directories: weeds out files that do not belong to list of acceptable file types.

You can set the list of acceptable files types in setAcceptable().

Parameters:
$directory [string]: which directory to search for invalid files; defaults to directory represented by this SnapExternalFile object
Returns:
[boolean]: success or failure


The documentation for this class was generated from the following file:

Generated on Wed Nov 24 02:03:16 2010 for Common by  doxygen 1.5.6