PHP File Upload Example

This tutorial will show you how to upload a file using PHP. In this example the file is selected using the browse button and file is uploaded to the ‘uploads’ directory. PHP script stores the file into the defined location and returns response as a success or failure message from the PHP script. As a validation step I have added only to check if you have selected a file for uploading or not.

Following steps are required in order to upload a file

1.  HTML page with upload field.

2.  PHP script to store the file.

Step 1. Put the below upload form fields inside <body/> tag in php page file_upload.php

Step 2. Create file_upload.php file with below source code

Step 3. Create the uploads directory in the same place where you have put file_upload.php

If we combine the steps 1, 2, and 3 then the full source code would be as shown below in a file called file_upload.php

Now if you run the above file then you will see below output in the browser

php file upload

When file successfully uploaded

php file upload

Thanks for reading.


Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.