Php File Uploading

A PHP script can be used with a HTML form to allow users to upload files to the server. Initially files are uploaded into a temporary directory and then relocated to a target destination by a PHP script.

PHP file upload features allows you to upload binary and text files both. Moreover, you can have the full control over the file to be uploaded through PHP authentication and file operation functions.

Creating an upload form

The following HTM code below creates an uploader form. This form is having method attribute set to post and enctype attribute is set to multipart/form-data.

Example :-

Note : Please copy the example and run on your own browser for showing result

Creating an upload script

There is one global PHP variable called $_FILES. This variable is an associate double dimension array and keeps all the information related to uploaded file.

  • $_FILES['file']['tmp_name'] - the uploaded file in the temporary directory on the web server.
  • $_FILES['file']['name'] - the actual name of the uploaded file.
  • $_FILES['file']['size'] - the size in bytes of the uploaded file.
  • $_FILES['file']['type'] - the MIME type of the uploaded file.
  • $_FILES['file']['error'] - the error code associated with this file upload.
  • Example :-

    Note : Please copy the example and run on your own browser for showing result