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_file

The name of the original (uploaded) file

$the_temp_file

The temporay name of the uploaded file

$file_copy

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!

$upload_dir

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!

$replace

Set this var to true if an existing file should be replaced (default = false)

$do_filename_check

This var is used as a switch, possible setting y/n. In position 'y' the name is validated while using regular expressions.

$max_length_filename

Set this value to take care of the maximum length of a filename (default = 100)

$extensions

This array holds all the file extensions allowed for an upload, you can add so much as you want.

$ext_string

This var is used for output the allowed file extensions.

$language

You need this var if your messages should be in an other language then English

$http_error

This variable is required, it holds the error reported by $_FILES array.

$rename_file

Set this boolean if you want to (auto)rename a file (I use a timestamp as a random filename)

$message

This array acts as a container for all messages generated during the upload process.

$create_directory

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)

file_upload()

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

error_text($err_num)

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

show_error_string()

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)

check_file_name()

Checks the "spelling" of a filename, the length and if the name value is not empty.

get_extension($from_file)

Isolate the files extension with this method

validateExtension()

This method checks for a valid file extension

show_extensions()

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

Check if the upload directory exists or not and if the boolean "$create_directory" is true the directory will be created.

existing_file()

This method checks if a file already exists