|
pclib
3.2.0
Lightweight PHP framework
|
Provides file management functions. More...
Public Member Functions | |
| __construct ($rootDir) | |
| getFile ($loc, $withContent=false) | |
| Return file from location $loc. More... | |
| setFile ($loc, $data) | |
| Store file $data into location $loc (insert or update). More... | |
| copyFile ($path, $loc) | |
| Copy file from directory path $path into filestorage location $loc. More... | |
| deleteFile ($loc) | |
| Delete file into location $loc. More... | |
| getFiles ($loc) | |
| Return array of all files assigned to entity $loc. More... | |
| setFiles ($loc, $files) | |
| Store all $files into file storage and assign it to entity $loc. More... | |
| deleteFiles ($loc) | |
| Delete all files assigned to entity $loc. More... | |
| postedFiles ($input_id=null) | |
| Return array of files submitted by some form. More... | |
| output ($loc, $showDownload=false) | |
| Output file $loc (such as image or pdf) into the browser. More... | |
| isImage ($file) | |
| Check if file is image. | |
| fileInBlackList ($fileName) | |
| Test if uploaded filename mask is on the blacklist. | |
| getErrorMessage ($code) | |
| Return upload error message. | |
Public Member Functions inherited from BaseObject | |
| loadDefaults ($className=null) | |
| Load default parameters of class $className into object instance. | |
| setProperties (array $defaults) | |
| Set public properties of object from the array. More... | |
| toArray () | |
| Convert object to array. More... | |
Data Fields | |
| $TABLE = 'FILESTORAGE' | |
| Database table name. | |
| $errors = [] | |
| If upload error occurs, this will contains error messages. | |
| $fileNameFormat = "{ENTITY_TYPE}_{HASH}.{EXT}" | |
| You can use fields: HASH,EXT,ORIGNAME,ORIGNAME_NORMALIZED,FILE_ID or any field from $entity. | |
| $dirNameFormat = '' | |
| Unused - always "/Y/n/" in this version. | |
| $uploadBlackList = ['*.php','*.php?','*.phtml','*.exe','.htaccess'] | |
| Files matching patterns cannot be uploaded. | |
Data Fields inherited from BaseObject | |
| $serviceLocator | |
| var function() Return service object when requested with service(). | |
Protected Member Functions | |
| insertFile (array $loc, array $data) | |
| Upload new file into filesystem and create db record. | |
| normalize ($filename) | |
| Sanitize filename. More... | |
| getDir ($format, $file) | |
| Create and return directory name where file $file will be stored. More... | |
| getFileName ($format, $file) | |
| Return filename used for storing particular $file. More... | |
Protected Member Functions inherited from BaseObject | |
| service ($service, $default=null) | |
| Try acquire $service and load it into property $this->$service. More... | |
Protected Attributes | |
| $rootDir = '' | |
| Path to your writable storage directory. | |
Additional Inherited Members | |
Static Public Member Functions inherited from BaseObject | |
| static | defaults () |
| Set or retireve default parameters of the object. More... | |
Provides file management functions.
You can upload, store, list and manage files.
| __construct | ( | $rootDir | ) |
| $rootDir | Path to your writable storage directory. |
| copyFile | ( | $path, | |
| $loc | |||
| ) |
Copy file from directory path $path into filestorage location $loc.
| string | $path | Full source path |
| int | array | $loc | Target location |
| deleteFile | ( | $loc | ) |
Delete file into location $loc.
| int | array | $loc | File location |
| deleteFiles | ( | $loc | ) |
Delete all files assigned to entity $loc.
| int | array | $loc | [entity-type, entity-id] |
|
protected |
Create and return directory name where file $file will be stored.
It is creating and using '/Year/month/' directories by default. Parameters $format and $file are unused in current version.
| getFile | ( | $loc, | |
$withContent = false |
|||
| ) |
Return file from location $loc.
| int | array | $loc | File location |
| bool | $withContent | Return content of the file too |
|
protected |
Return filename used for storing particular $file.
You can setup filename format by setting attribute FileStorage->fileNameFormat.
| $format | Format string e.g. "PREFIX_{ORIGNAME_NORMALIZED}.{EXT}"; | |
| array | $file | File information (Any field can be used in $format string) |
| getFiles | ( | $loc | ) |
Return array of all files assigned to entity $loc.
| int | array | $loc | [entity-type, entity-id] |
|
protected |
Sanitize filename.
Replace non-ascii characters, remove diacriticts and replace whitespaces with '_'.
| output | ( | $loc, | |
$showDownload = false |
|||
| ) |
Output file $loc (such as image or pdf) into the browser.
| int | array | $loc | file location (you can use integer id too) |
| bool | $showDownload | Should browser show download dialog? |
| postedFiles | ( | $input_id = null | ) |
Return array of files submitted by some form.
You can store them by function setFiles().
| string | $input_id | If present, it will return data from this input only |
| setFile | ( | $loc, | |
| $data | |||
| ) |
Store file $data into location $loc (insert or update).
| int | array | $loc | File location |
| array | $data | File data |
| setFiles | ( | $loc, | |
| $files | |||
| ) |
Store all $files into file storage and assign it to entity $loc.
| int | array | $loc | [entity-type, entity-id] |
| array | $files | List of files |