This PHP upload class can be used to build scripts and applications with the feature to upload files to a web server. The PHP script has features like: file-extension check, renaming files, file name validation, maximum file- size limitation, MIME type detection and a flexible error reporting system. The class is extremely easy to use and comes together with full working examples. Since version 2.x the is a class extension that makes it easier for the developer to upload multiple files. Check the example files and class file for all update information. Since version 2.22 the class is written to handle requests if the PHP directive "register_globals=off". Since version 2.25 there is a class extension for photo uploads. This extension is upload photos (images) and resize them to a given maximum width and height. Since version 2.26 there is support for the ImageMagick command line tools. This feature is an option and works faster then PHP functions from the GD library.
The name of the original (uploaded) file
The temporay name of the uploaded file
A switch do enable/disable MIME type detection
The directory where the file will be uploaded. A non existing directory will be created. Currently the is support for a new directory one level above the existing directory!
Set this var to true if an existing file should be replaced (default = false)
This var is used as a switch, possible setting y/n. In position 'y' the name is validated while using regular expressions.
Set this value to take care of the maximum length of a filename (default = 100)
This array holds all the file extensions allowed for an upload, you can add so much as you want.
An array with most common MIME types. Used to validate a file's MIME type.
This var is used for output the allowed file extensions.
You need this var if your messages should be in an other language then English
This variable is required, it holds the error reported by $_FILES array.
Set this boolean if you want to (auto)rename a file (I use a timestamp as a random filename)
This var holds the new name after upload (note this name might be different from the uploaded file if you rename/copy the file)
Use this variable always if you save the filename in a database or in a variable!
This array acts as a container for all messages generated during the upload process.
Switch this boolean to create the upload directory if it doesn't exist (one level up, read also the information about the variable >$upload_dir)
The constructor, sets the language, the rename boolean and empties the file extension string.
This method is used to show all strings inside the message array
Checks if a custom filename exists, sets a default (new) filename or keeps the original one
This method is used to handle the upload process, $to_name is an additional custom name parameter (works together with the rename boolean)
Checks the "spelling" of a filename, the length and if the name value is not empty.
Isolate the files extension with this method
Checks if the current MIME type is equal to the type from the extension
This method checks for a valid file extension
Use this method to build the "allowed" extensions string
This method is a group of functions which move the temporary file to his propper upload direction.
Check if the upload directory exists or not and if the boolean "$create_directory" is true the directory will be created.
This method checks if a file already exists
Simple function to show file information like: file size, file name, MIME type and image dimensions (if available)
Get the MIME type for a file. The function is using the Fileinfo extension or mime_content_type() for older systems.
A flexible function to delete an uploaded file.
A dynamic input/file form field with a switch to show a file or the form field.
This method is a multilanguage error selector, the property holds the error number