Easy and secure managment of files submitted via HTML forms.
This package provides an advanced system for managing uploads of files via HTML <input type="file" /> fields. Features include:
In the following examples it is assumed that you are using an HTML form field <input type="file" name="f" /> in order to upload files. For example:
Example 48-30. HTML form for simple file upload
The following form can be used in order to test the single file upload example.
Example 48-31. Simple file upload
The following code looks at the request and checks if a valid file was uploaded through the form. If that is the case, the file is moved to the subdirectory uploads.
Example 48-32. HTML form for multiple file upload
The following form can be used in order to test the multiple file upload example.
Example 48-33. Multiple files, more extensive checks
Multiple files can uploaded by replacing the name of the form field (f) with f and creating multiple <input /> fields with this name.
HTTP_Upload provides extensive information about uploaded files via the getProp() method:
If no value for name is provided, then this method will return an array containing all available information about the uploaded file. Otherwise the information identified by the value of this parameter will be returned as a string.
The list of possible values is determined by the contents of the $_FILES array, but is customized for the purposes of HTTP_Upload. Here are the possible properties:
'name': destination file name
'tmp_name': temporary uploaded file name (assigned by PHP)
'form_name': name of the HTML form that submitted the uploaded file
'type': Mime type of the file
'size': size of the file
'error': if there was an error on upload, this contains a string representing the kind of error. The errorCode() method can be used to retrieve a localized error message from this property.
Example 48-34. Extensive information via getProp()
Another handy feature of HTTP_Upload is support for internationalized error messages. This means that if an error (like an invalid file upload) is detected, the programmer can choose in which the language the error messages should be returned by HTTP_Upload.
The first parameter of the constructor method for HTTP_Upload determines the language to be used. This is illustrated in the following example:
Example 48-35. Example