
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. | |
| updateDB () | |
| updates or inserts the file's path and id /* | |
| weedFiles ($directory= 'default') | |
| For directories: weeds out files that do not belong to list of acceptable file types. | |
Private Member Functions | |
| generateFilePaths ($fileName, $origFileName) | |
| Generates URL and full paths to file/directory. | |
| generateRelPath ($fileName, $origFileName) | |
| Generates base path using md5 hasing. | |
There are several things we may want to do with it.
Definition at line 14 of file SnapExternalFile.php5.
| SnapExternalFile::__construct | ( | $ | version, | |
| $ | array = "" | |||
| ) |
Create a new SnapExternalFile attached to a version.
| $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()) |
Definition at line 28 of file SnapExternalFile.php5.
References load().
| 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.
| $newName | [string]: optional new name for copy |
Definition at line 292 of file SnapExternalFile.php5.
| 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.
| $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 |
| $tmpFile | [TYPE]: DESCRIPTION | |
| $originalName | [TYPE]: DESCRIPTION | |
| $name | [TYPE]: DESCRIPTION |
Definition at line 216 of file SnapExternalFile.php5.
References copy(), generateFilePaths(), and SObject::setError().
| SnapExternalFile::delete | ( | ) |
Destroy this file.
Destroy the file on the filesystem.
Definition at line 313 of file SnapExternalFile.php5.
| SnapExternalFile::generateFilePaths | ( | $ | fileName, | |
| $ | origFileName | |||
| ) | [private] |
Generates URL and full paths to file/directory.
The URL is essentially "/media" plus the base path from generateRelPath(). The Path is essentially /var/www/html/media" plus the base path from generateRelPath(). The prefixes are derived from the Snap2 configuration.
| $fileName | [string]: path to source file on filesystem | |
| $origFileName | [string]: original name of file if different from what's in the path |
Definition at line 391 of file SnapExternalFile.php5.
References generateRelPath().
Referenced by create().
| SnapExternalFile::generateRelPath | ( | $ | fileName, | |
| $ | origFileName | |||
| ) | [private] |
Generates base path using md5 hasing.
For internal use only.
Basically, the contents of the file (or listing of files in the directory) are combined with the current time, the name of the file and the original file name and hashed using MD5, which is then base64-encoded into a 32 character string. The first three characters are used as names in a hierarchy of directories and the remaining 29 characters form the filename, to which is appended the original suffix of the filename. All of this is used when uploading the files to the media directory. They need a hashed filename.
| $fileName | [string]: path to source file on filesystem | |
| $origFileName | [string]: original file name, should it differ from the actual filename given in $fileName |
Definition at line 357 of file SnapExternalFile.php5.
References SObject::setError().
Referenced by generateFilePaths().
| 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.
Definition at line 126 of file SnapExternalFile.php5.
| 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.
Definition at line 115 of file SnapExternalFile.php5.
| SnapExternalFile::getPath | ( | ) |
Retrieves path on the server where file is located.
Definition at line 40 of file SnapExternalFile.php5.
| SnapExternalFile::getURL | ( | ) |
Retrieves URL to file.
Definition at line 49 of file SnapExternalFile.php5.
| SnapExternalFile::load | ( | $ | array | ) |
Loads file information from serialized array generated by getArray().
| $array | [array]: representation of the file |
Definition at line 135 of file SnapExternalFile.php5.
References SObject::setError().
Referenced by __construct().
| 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())
| $fileTypes | [array]: list of file suffixes that are acceptable |
Definition at line 157 of file SnapExternalFile.php5.
References SObject::setError().
| 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.
Definition at line 60 of file SnapExternalFile.php5.
References copy().
| 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.
| $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... |
Definition at line 269 of file SnapExternalFile.php5.
| SnapExternalFile::updateDB | ( | ) |
updates or inserts the file's path and id /*
For internal use only.
/*
Definition at line 335 of file SnapExternalFile.php5.
| 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().
| $directory | [string]: which directory to search for invalid files; defaults to directory represented by this SnapExternalFile object |
Definition at line 174 of file SnapExternalFile.php5.
1.5.6