fUploadclassv1.0.0b10
Provides validation and movement of uploaded files
| 1.0.0b10 | BackwardsCompatibilityBreak - renamed setMaxFilesize() to setMaxSize() to be consistent with fFile::getSize() 5/30/10 |
|---|---|
| 1.0.0b9 | BackwardsCompatibilityBreak - the class no longer accepts uploaded files that start with a . unless allowDotFiles() is called - added setOptional() 5/30/10 |
| 1.0.0b8 | BackwardsCompatibilityBreak - validate() no longer returns the $_FILES array for the file being validated - added $return_message parameter to validate(), fixed a bug with detection of mime type for text files 5/26/10 |
| 1.0.0b7 | Added filter() to allow for ignoring array file upload field entries that did not have a file uploaded 10/6/09 |
| 1.0.0b6 | Updated move() to use the new fFilesystem::createObject() method 1/21/09 |
| 1.0.0b5 | Removed some unnecessary error suppression operators from move() 1/5/09 |
| 1.0.0b4 | Updated validate() so it properly handles upload max filesize specified in human-readable notation 1/5/09 |
| 1.0.0b3 | Removed the dependency on fRequest 1/5/09 |
| 1.0.0b2 | Fixed a bug with validating filesizes 11/25/08 |
| 1.0.0b | The 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
::compose() protected
Composes text using fText if loaded
Signatures
string compose( string $message, mixed $component )
string compose( mixed .. )
Parameters
| string | $message | The message to compose |
| mixed | $component | A string or number to insert into the message |
| mixed | .. | ... |
Returns
The composed and possible translated message
::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
->allowDotFiles() public
Sets the upload class to allow files starting with a .
Files starting with . may change the behaviour of web servers, for instance .htaccess files for Apache.
Signature
void allowDotFiles( )
->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|NULL 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, or NULL if no file was uploaded
Throws
- fValidationException
- When $directory is somehow invalid or validate() thows an exception
->setMaxSize() public
Sets the maximum size the uploaded file may be
This method should be used with the MAX_FILE_SIZE hidden form input since the hidden form input will reject a file that is too large before the file completely uploads, while this method will wait until the whole file has been uploaded. This method should always be used since it is very easy for the MAX_FILE_SIZE post field to be manipulated on the client side.
This method can only further restrict the upload_max_filesize ini setting, it can not increase that setting. upload_max_filesize must be set in the php.ini (or an Apache configuration) since file uploads are handled before the request is handed off to PHP.
Signature
void setMaxSize( 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 |
->setOptional() public
Sets the file upload to be optional instead of required
Signature
void setOptional( )
->validate() public
Validates the uploaded file, ensuring a file was actually uploaded and that is matched the restrictions put in place
Signatures
NULL|string validate( string $field, mixed $index=NULL, boolean $return_message )
NULL|string validate( string $field, boolean $return_message )
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 |
| boolean | $return_message | If any validation error should be returned as a string instead of being thrown as an fValidationException |
Returns
If $return_message is not TRUE or if no error occurs, NULL, otherwise a string error message
Throws
- fValidationException
- When no file is uploaded or the uploaded file violates the options set for this object
