File uploading with PHP

This post will explain you that how to upload an image on your web host from browser. First of all you need to make HTML form.


Simple HTML Code:

This form will send file to upload.php now make upload.php file.

PHP Code

Actual upload is very simple

This is very small piece of code upload file send to it by HTML

$target = “upload/”; is where we assign the folder that files will be uploaded to.

As you can see in the second line, this folder is relative to the upload.php file. So for example, if your file was at then it would upload files to Be sure you remember to create this folder!

Limit the File Size

You can change this line to be a larger or smaller size if you wish by changing 350000 to a different number.

Limit Files by Type

Above code checks whether user upload a .php file or not.

In this block we restrict user to upload only .gif file.