fUploadclassv1.0.0b7

Provides validation and movement of uploaded files

Changes:
1.0.0b7Added filter() to allow for ignoring array file upload field entries that did not have a file uploaded 10/6/09
1.0.0b6Updated move() to use the new fFilesystem::createObject() method 1/21/09
1.0.0b5Removed some unnecessary error suppression operators from move() 1/5/09
1.0.0b4Updated validate() so it properly handles upload max filesize specified in human-readable notation 1/5/09
1.0.0b3Removed the dependency on fRequest 1/5/09
1.0.0b2Fixed a bug with validating filesizes 11/25/08
1.0.0bThe initial implementation 6/14/07

Static Methods

::check() public

Checks to see if the field specified is a valid file upload field

Signature

boolean check( string $field )

Parameters

string $field The field to check

Returns

If the field is a valid file upload field

::count() public

Returns the number of files uploaded to a file upload array field

Signature

integer count( string $field )

Parameters

string $field The field to get the number of files for

Returns

The number of uploaded files

::filter() public

Removes individual file upload entries from an array of file inputs in $_FILES when no file was uploaded

Signature

array filter( string $field )

Parameters

string $field The field to filter

Returns

The indexes of the files that were uploaded

Methods

->__get() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

All requests that hit this method should be requests for callbacks

Signature

callback __get( string $method )

Parameters

string $method The method to create a callback for

Returns

The callback for the method requested

->allowPHP() public

Sets the upload class to allow PHP files

Signature

void allowPHP( )

->enableOverwrite() public

Set the class to overwrite existing files in the destination directory instead of renaming the file

Signature

void enableOverwrite( )

->move() public

Moves an uploaded file from the temp directory to a permanent location

Signature

fFile move( string|fDirectory $directory, string $field, mixed $index=NULL )

Parameters

string|fDirectory $directory The directory to upload the file to
string $field The file upload field to get the file from
mixed $index If the field was an array file upload field, upload the file corresponding to this index

Returns

An fFile (or fImage) object

Throws

fValidationException
When $directory is somehow invalid or validate() thows an exception

->setMaxFileSize() public

Sets the file mime types accepted, one per parameter

Signature

void setMaxFileSize( string $size )

Parameters

string $size The maximum file size (e.g. 1MB, 200K, 10.5M) - 0 for no limit

->setMIMETypes() public

Sets the file mime types accepted

Signature

void setMIMETypes( array $mime_types, string $message )

Parameters

array $mime_types The mime types to accept
string $message The message to display if the uploaded file is not one of the mime type specified

->validate() public

Validates the uploaded file, ensuring a file was actually uploaded and that is matched the restrictions put in place

Signature

void validate( string $field, mixed $index=NULL )

Parameters

string $field The field the file was uploaded through
mixed $index If the field was an array of file uploads, this specifies which one to validate

Throws

fValidationException
When no file is uploaded or the uploaded file violates the options set for this object