Tutorial: How to make an Image Upload and Thumbnailer Script PHP

Pages: 1 2 3 4 5 6 7

1. Open up your thumb.php file and put this in above the html form:

What this piece of code does is it checks that the form has been submitted, and then checks to see if the uploaded file is of the right format. isset($_POST['submit']) looks to see if the post value of the submit button is present. If it is, then this if statement is valid and the processing will continue.

The next line sets up an array into $acceptedfiletypes variable. Inside the array are MIME type header values. We have added three to this array, all the files that we will allow to be uploaded and handled. They include jpgs, gif, and png. You can name the extension anything you want on the file, but it will only allow the file types in the array.

The third line gets the MIME type of the uploaded file and stores it into a variable for later use. So now the fourth line puts these two parts together. It uses the in_array function to see if the text in the $filetype variable is present in the $acceptedfiletypes array. If it is, i.e. in our case if it is an image, then it will come back as true and the code will continue executing. If not, it will return false and shout back to the user an error, ours is a bit bossy and says don't waste our time.

Pages: 1 2 3 4 5 6 7

  1. 3 Responses to “Tutorial: How to make an Image Upload and Thumbnailer Script PHP”

  2. By paparanch PHILIPPINES Windows Vista Mozilla Firefox 2.0.0.14 on Jun 16, 2008

    i don’t whats the problem with this because when i uploaded a gif file…its not animating anymore…why?

  3. By pouria ISLAMIC REPUBLIC OF IRAN Windows XP Internet Explorer 6.0 on Aug 7, 2008

    hi :)
    i recive this error with every kind of images :
    File is not an image! Don’t waste my time!

    so whats the problem?

  4. By sohn THAILAND Windows XP Mozilla Firefox 3.0.3 on Oct 8, 2008

    That’s cool. I test it and it really Great!!

Post a Comment