
Provides validation and movement of uploaded files
1.0.0b15 | Fixed an undefined variable error in setMaxSize() 9/16/12 |
---|---|
1.0.0b14 | Fixed some method signatures 8/24/11 |
1.0.0b13 | Changed the class to throw fValidationException objects instead of fProgrammerException objects when the form is improperly configured - this is to prevent error logs when bad requests are sent by scanners/hackers 8/24/11 |
1.0.0b12 | Fixed the filter() callback constant 11/24/10 |
1.0.0b11 | Added setImageDimensions() and setImageRatio() 11/11/10 |
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 |
Checks to see if the field specified is a valid file upload field
boolean check( string $field, boolean $throw_exception=TRUE )
string | $field | The field to check |
boolean | $throw_exception | If an exception should be thrown when there are issues with the form |
If the field is a valid file upload field
Composes text using fText if loaded
string compose( string $message, mixed $component [, ... ] )
string | $message | The message to compose |
mixed | $component [, ... ] | A string or number to insert into the message |
The composed and possible translated message
Returns the number of files uploaded to a file upload array field
integer count( string $field )
string | $field | The field to get the number of files for |
The number of uploaded files
Removes individual file upload entries from an array of file inputs in $_FILES when no file was uploaded
array filter( string $field )
string | $field | The field to filter |
The indexes of the files that were uploaded
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
callback __get( string $method )
string | $method | The method to create a callback for |
The callback for the method requested
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.
void allowDotFiles( )
Sets the upload class to allow PHP files
void allowPHP( )
Set the class to overwrite existing files in the destination directory instead of renaming the file
void enableOverwrite( )
Moves an uploaded file from the temp directory to a permanent location
fFile|NULL move( string|fDirectory $directory, string $field, mixed $index=NULL )
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 |
An fFile (or fImage) object, or NULL if no file was uploaded
Sets the allowable dimensions for an uploaded image
void setImageDimensions( integer $min_width, integer $min_height, integer $max_width=0, integer $max_height=0 )
integer | $min_width | The minimum width - 0 for no minimum |
integer | $min_height | The minimum height - 0 for no minimum |
integer | $max_width | The maximum width - 0 for no maximum |
integer | $max_height | The maximum height - 0 for no maximum |
Sets the allowable dimensions for an uploaded image
void setImageRatio( numeric $width, numeric $height, string $allow_excess_dimension )
numeric | $width | The minimum ratio width |
numeric | $height | The minimum ratio height |
string | $allow_excess_dimension | The dimension that should allow for excess pixels |
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.
void setMaxSize( string $size )
string | $size | The maximum file size (e.g. 1MB, 200K, 10.5M) - 0 for no limit |
Sets the file mime types accepted
void setMIMETypes( array $mime_types, string $message )
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 |
Sets the file upload to be optional instead of required
void setOptional( )
Validates the uploaded file, ensuring a file was actually uploaded and that is matched the restrictions put in place
NULL|string validate( string $field, mixed $index=NULL, boolean $return_message=NULL )
NULL|string validate( string $field, boolean $return_message=NULL )
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 |
If $return_message is not TRUE or if no error occurs, NULL, otherwise a string error message