pclib  2.3.2
Lightweight PHP framework
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
FileStorage Class Reference

Provides file management functions. More...

Inheritance diagram for FileStorage:
BaseObject

Public Member Functions

 __construct ($rootdir)
 
 saveFile ($entity, $file)
 Save file and assign it to the entity. More...
 
 save ($entity, $files)
 Save all files in $files array and assign these files to entity $entity. More...
 
 postedFiles ($input_id=null)
 Return array of posted files coming from php array _FILES. More...
 
 getEntity ($id)
 Return entity of the record from FILESTORAGE table.
 
 deleteAll ($filter)
 Delete multiple files according $filter array.
 
 delete ($id)
 Delete file with primary key $id.
 
 deleteEntity ($entity)
 Delete all files linked with $entity.
 
 output ($id, $attachment=false)
 Output file $id to the end-user.
 
 isImage ($file)
 Check if file is image.
 
 findAll ($filter)
 Return list of all files (rows from db-table) according used filter. More...
 
 findOne ($filter)
 Return particular file (row from db-table) according used filter. More...
 
 getAll ($entity)
 Return list of all files assigned to $entity. More...
 
 getOne ($entity, $file_id=null)
 Return particular file (row from db-table) for entity $entity.
 
 fileInBlackList ($fileName)
 Test if uploaded filename mask is on the blacklist. More...
 
 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...
 
 addEvent ($name, $callback)
 Add event handler to $object->$name property. More...
 
 toArray ()
 Convert object to array. More...
 

Data Fields

 $TABLE = 'FILESTORAGE'
 Database table name. More...
 
 $errors = array()
 If upload error occurs, this will contains error messages. More...
 
 $fileNameFormat = "{PREFIX}{HASH}.{EXT}"
 You can use fields: HASH,EXT,ORIGNAME,ORIGNAME_NORMALIZED,FILE_ID or any field from $entity. More...
 
 $dirNameFormat = ''
 Unused - always "/Y/n/" in this version. More...
 
 $onBeforeSave
 Occurs before file is saved. More...
 
 $onAfterSave
 Occurs after file is saved. More...
 
 $uploadBlackList = array('*.php','*.php?','*.phtml','*.exe','.htaccess')
 Files matching patterns cannot be uploaded. More...
 
- Data Fields inherited from BaseObject
 $onNewInstance
 Occurs when new instance of the class is created. More...
 
 $onMissingMethod
 Occurs when called method does not exist. More...
 
 $serviceLocator
 var function() Return service object when requested with service(). More...
 

Protected Member Functions

 updateMeta ($entity, $file)
 Update file metadata.
 
 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
 fireEvent ($name, array $args=array())
 Run all event handlers in $object->$name property. More...
 
 service ($service, $default=null)
 Try acquire $service and load it into property $this->$service. More...
 

Protected Attributes

 $rootdir
 Path to your writable storage directory. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseObject
static defaults ()
 Set or retireve default parameters of the object. More...
 

Detailed Description

Provides file management functions.

You can upload, store, list and manage files.

Constructor & Destructor Documentation

__construct (   $rootdir)
Parameters
$rootdirPath to your writable storage directory.

Member Function Documentation

fileInBlackList (   $fileName)

Test if uploaded filename mask is on the blacklist.

findAll (   $filter)

Return list of all files (rows from db-table) according used filter.

You can use any fields for filtering.

findOne (   $filter)

Return particular file (row from db-table) according used filter.

You can use any fields for filtering.

getAll (   $entity)

Return list of all files assigned to $entity.

You can use any fields for filtering.

getDir (   $format,
  $file 
)
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.

getFileName (   $format,
  $file 
)
protected

Return filename used for storing particular $file.

You can setup filename format by setting attribute FileStorage->fileNameFormat.

Parameters
$formatFormat string e.g. "PREFIX_{ORIGNAME_NORMALIZED}.{EXT}";
array$fileFile information (Any field can be used in $format string)
normalize (   $filename)
protected

Sanitize filename.

Replace non-ascii characters, remove diacriticts and replace whitespaces with '_'.

postedFiles (   $input_id = null)

Return array of posted files coming from php array _FILES.

Example: $fs->save($entity, $fs->postedFiles()); Example: $file = postedFiles('FILE_1'); //Read FILE_1 form field

Parameters
$input_idIf present, it will return data from one input only
save (   $entity,
  $files 
)

Save all files in $files array and assign these files to entity $entity.

Parameters
$entityassociative array with entity data
$filesFiles to upload coming from method postedFiles()
See also
saveFile()
saveFile (   $entity,
  $file 
)

Save file and assign it to the entity.

If file FILE_ID already exists, it is rewritten. $file is array coming from function postedFiles() $entity must contains fields ID,TYPE identifying to what entity file is assigned. Except this fields, it can contains any optional fields.

Parameters
$entityassociative array with entity data
$fileassociative array with file to upload informations. See postedFiles().

Field Documentation

$dirNameFormat = ''

Unused - always "/Y/n/" in this version.

$errors = array()

If upload error occurs, this will contains error messages.

$fileNameFormat = "{PREFIX}{HASH}.{EXT}"

You can use fields: HASH,EXT,ORIGNAME,ORIGNAME_NORMALIZED,FILE_ID or any field from $entity.

$onAfterSave

Occurs after file is saved.

$onBeforeSave

Occurs before file is saved.

$rootdir
protected

Path to your writable storage directory.

$TABLE = 'FILESTORAGE'

Database table name.

$uploadBlackList = array('*.php','*.php?','*.phtml','*.exe','.htaccess')

Files matching patterns cannot be uploaded.


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