≡ Menu

Upload Class For PHP

class.upload.php – Free PHP Upload Class

This PHP script uploads files and manipulates images very easily. The perfect script to generate thumbnails or create a photo gallery! It can convert, resize and work on uploaded images in many ways, add labels, watermarks and reflections and other image editing features. You can use it for files uploaded through an HTML form, a Flash uploader, or on local files. It uses the GD library. This script is released under the GPL Version 2.

If your project is not GPL, commercial licenses are available.

Look at the example below:

 $foo = new Upload($_FILES['form_field']); if ($foo->uploaded) { // save uploaded image with no changes $foo->Process('/home/user/files/'); if ($foo->processed) { echo 'original image copied'; } else { echo 'error : ' . $foo->error; } // save uploaded image with a new name $foo->file_new_name_body = 'foo'; $foo->Process('/home/user/files/'); if ($foo->processed) { echo 'image renamed "foo" copied'; } else { echo 'error : ' . $foo->error; } // save uploaded image with a new name, // resized to 100px wide $foo->file_new_name_body = 'image_resized'; $foo->image_resize = true; $foo->image_convert = gif; $foo->image_x = 100; $foo->image_ratio_y = true; $foo->Process('/home/user/files/'); if ($foo->processed) { echo 'image renamed, resized x=100 and converted to GIF'; $foo->Clean(); } else { echo 'error : ' . $foo->error; } } 

What does it actually do in this example?

This example uses a file uploaded via a form. With this single file, it will :

  • copy the file without any modification
  • copy the file after having changed its name to ‘foo’
  • copy the file, resizing it to x=100, y=auto, converting it to GIF

Why use this class?

  • with one uploaded file, you can do as many copies, convertions, resizing you want.
  • you can resize each image dimension, or both, keeping the image ratio or not.
  • you can choose to resize an image only if it is bigger -or smaller- than the wanted sizes
  • you can manipulate the image in many ways, play with colors, add borders, labels and watermarks…
  • its use is simplistic but powerful
  • you can work on uploaded files or local files, useful for batch processing
  • Flash uploaders are fully supported
  • MIME type detection is very comprehensive
  • more than 60 documented configuration settings
  • a lot of variables are set up during the process. You can retrieve all these values after a process.
  • error messages are understandable, and a variable log allows you to see what the class does.
  • it is already widely used on Internet
  • it is free 🙂

If you like this script and are looking for some thing just like this than grab this script by going on to its website at : Class.upload.php Website

{ 8 comments… add one }
  • aram May 29, 2009, 3:17 am

    very important post

    thanx so much

    • Zubair May 29, 2009, 3:45 am

      Thanks aram, glad you found this useful 🙂

  • Ahmad Mushtaq May 29, 2009, 6:25 am

    Hello Zobair!

    Nice post… You seems to me a nice person. Whats your email by the way?

  • Jessica Lopez September 7, 2009, 10:29 am

    Thank you for your help!

  • Lovetta Graydon March 7, 2010, 6:03 am

    Hey I found your blog by luck on google while trying to find something really unrelated but I am very happy that I did, You have just added yourself another subscriber. 🙂

  • Junior Feistner June 12, 2010, 2:13 am

    This is a very interesting post, I was looking for this knowledge. Just so you know I discovered your weblog when I was looking around for blogs like mine, so please check out my site sometime and leave me a comment to let me know what you think.

  • Alexander September 1, 2010, 1:05 pm

    Thanks for sharing this Zubair, i was just looking for something like this and am glad i found this post of yours.

    P.S:- Nice & Clean Layout you have here 🙂

    • Zubair September 3, 2010, 3:07 pm

      Thanks Alexander
      I’m glad you found this post useful, i’ll be sharing more stuff like these so please feel free to subscribe to the feed 🙂

Leave a Comment