June 23, 2012 5:34 pm

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 www.yours.com/files/upload.php then it would upload files to www.yours.com/files/upload/yourfile.gif. 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.

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.

Tutorial Categories:
  • Great tutorial.
    It is very easy and helpful for new PHP programmer like me.

  • this saved my time….thanks huzoor

  • Gaurav

    very helpful site I ever got……

    • huzoorbux

      Thanks @3bb49aa28e0a0374d28286dc755b4513:disqus

  • milan

    thanx phpgang

  • didn’t apply any security , so it’s not secure to use in public !