Upload any file using a PHP Script

This PHP upload class (the old name) can be used to upload files with a client browser to a remote web server location. The features in the first release are: file-extension check, maximum file- size limitation and a flexible error reporting system. The class is extremely easy to use and comes together with full working examples. Since the second version is it possible to upload multiple files. Check the class file for all update information. The version 2.22 (and higher) is compatible with the PHP directive "register_globals=off". NEW functions for the multiple upload function: rename files and filename validation. With the updated (version 2.25) photo upload extension it's possible to upload photos (logos) and resize them to the maximum X and Y size. Since version 2.26 the is support for the ImageMagick command line tools as an option (works faster then functions of the GD library). Note the database example since the last version.

Visit here Script Demo - PHP Script Download

Documentation and support

All update information - Post here your questions and suggestions.

Related forum posts

Variables (upload_class.php)


The name of the original (uploaded) file


The temporay name of the uploaded file


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!


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.


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 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)

Methodes (upload_class.php)


The constructor, sets the language, the rename boolean and empties the file extension string.


This method is a multilanguage error selector, the property holds the error number


This method is used to show all strings inside the message array

set_file_name($new_name = "")

Checks if a custom filename exists, sets a default (new) filename or keeps the original one

upload($to_name = "")

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


This method checks for a valid file extension


Use this method to build the "allowed" extensions string

move_upload($tmp_file, $new_file)

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