Smart Multi-Uploader and Thumbnail Creator from GIF/ JPEG/ PNG with PHP

Image uploader and thumbnail generatorThis is a multiple image uploader with flexible thumbnail generator. You can set how many images you want to upload at once. This script creates thumbnails automagically from GIF / JPEG and PGN images. You can also disable thumbnails completely. You can change easily path/to/upload and thumbnails max width and height. Script dedect automagically which dimestion to use for resize. It checks image-type and max-image-size. Comments and featurequest are welcome!


* Smart Image Uploader by
* Free for private use
* Please support us with donations or backlinks

$upload_image_limit = 5; // How many images you want to upload at once?
$upload_dir			= ""; // default script location, use relative or absolute path
$enable_thumbnails	= 1 ; // set 0 to disable thumbnail creation

##################### THUMBNAIL CREATER FROM GIF / JPG / PNG
function make_thumbnails($updir, $img){

	$thumbnail_width	= 80;
	$thumbnail_height	= 60;
	$thumb_preword		= "thumb_";

	$arr_image_details	= GetImageSize("$updir"."$img");
	$original_width		= $arr_image_details[0];
	$original_height	= $arr_image_details[1];

	if( $original_width > $original_height ){
		$new_width	= $thumbnail_width;
		$new_height	= intval($original_height*$new_width/$original_width);
	} else {
		$new_height	= $thumbnail_height;
		$new_width	= intval($original_width*$new_height/$original_height);

	$dest_x = intval(($thumbnail_width - $new_width) / 2);
	$dest_y = intval(($thumbnail_height - $new_height) / 2);

	if($arr_image_details[2]==1) { $imgt = "ImageGIF"; $imgcreatefrom = "ImageCreateFromGIF";  }
	if($arr_image_details[2]==2) { $imgt = "ImageJPEG"; $imgcreatefrom = "ImageCreateFromJPEG";  }
	if($arr_image_details[2]==3) { $imgt = "ImagePNG"; $imgcreatefrom = "ImageCreateFromPNG";  }

	if( $imgt ) { 
		$old_image	= $imgcreatefrom("$updir"."$img");
		$new_image	= imagecreatetruecolor($thumbnail_width, $thumbnail_height);


################################# UPLOAD IMAGES
		foreach($_FILES as $k => $v){ 

			$img_type = "";

			### $htmo .= "$k => $v"; 	### print_r($_FILES);

			if( !$_FILES[$k]['error'] && preg_match("#^image/#i", $_FILES[$k]['type']) && $_FILES[$k]['size'] < 1000000){

				$img_type = ($_FILES[$k]['type'] == "image/jpeg") ? ".jpg" : $img_type ;
				$img_type = ($_FILES[$k]['type'] == "image/gif") ? ".gif" : $img_type ;
				$img_type = ($_FILES[$k]['type'] == "image/png") ? ".png" : $img_type ;

				$img_rname = $_FILES[$k]['name'];
				$img_path = $upload_dir.$img_rname;

				copy( $_FILES[$k]['tmp_name'], $img_path ); 
				if($enable_thumbnails) make_thumbnails($upload_dir, $img_rname);
				$feedback .= "Image and thumbnail created $img_rname
"; } } ############################### HTML FORM while($i++ < $upload_image_limit){ $form_img .= 'Image '.$i.':
'; } $htmo .= ' '.$feedback.' '.$form_img.'
Powered by Cafe Webmaster '; echo $htmo;
Download multi-image_uploader_thumbnail_creator.zip1.39 KB


This is an awesome script

I was busy developing a site that allowed members to upload images for there own galleries. I was really struggling to create gif thumbnails and this script did everything I wanted and was so easy to implement. THANX


Hi! It works great and is easy to use, but the resized images are of really low quality. What am i doing wrong?

This is a typical PHP+GD

This is a typical PHP+GD issue. Resized small images are low quality.

my thumbnail pictues is to low quality?

Hi. Firstly thanks for your great code. But i have a problem. With this code , my upload's thumbnail pictures are to low quality. Normal size pictures is the same as before uploading but small pictures is worse.

What must i do to be have hşgh quality thumb pictures.

Thanks to alot.
İf any body wawnt to help me , he can mail me :

See you soon

Code updated: high quality thumbnails

Code updated: imagecreate replaced with imagecreatetruecolor!

Now thumbnails are high quality.

Thumnails not working

Thumbnails not working..and only one image gets uploaded

it is working

just tested with 4 images, 1 gif + 1 png + 2 jpeg and it works. all images uploaded and thumbnails created. check your server + permissions.

Adding photos to Mysql database

How would you go about getting the name of each photo so it can be added to a mysql database? I know how to add single items from a form into a mysql database, but I'm not sure how it would work with the "for" loop you have.

Not working with transparency

it doesn't work for images with transparency, it becomes black :(

Sub Directory

How could this be set to upload the thumbnail to a sub-directory.? Great script btw..

Excelente script, funciona

Excelente script, funciona perfectamente. Gracias.

what dose this code do can u

what dose this code do can u put it on your website

Many Thanks

Thank you very much, you script work like a charm, awesome script and easy to customize. Cheers.
Greetings from Sri Lankan programmer.

Thumbs Low quality, and the same path

Thank for your coding, i have integrate it working fine,
but the thumbs is low quality, and in the same folder,

Can you tell me how customize this code to upload with high quality thumbs
and device big image and thumbs difference folder

my email:

Thank you so much,

MySQL integration....

I have a question about integrating this with mysql, for some reason the upload works but the insert into query is not.
Where should the insert query be called in this script? I have it run where the foreach($_FILES as $k .... is

I am sure it is an easy fix, but this one has me stumped.


Hi great script! one qick

great script!

one qick question
I need to put in my mysql links of uploaded images but I cnat figu out how!
Pleas help!

get these errors. how do i

get these errors. how do i fix them.

Notice: Undefined variable: i in C:\xampp\htdocs\toserver\insertneed\test\addphoto.php on line 51

Notice: Undefined variable: form_img in C:\xampp\htdocs\toserver\insertneed\test\addphoto.php on line 52

Notice: Undefined variable: feedback in C:\xampp\htdocs\toserver\insertneed\test\addphoto.php on line 56

Notice: Undefined variable: htmo in C:\xampp\htdocs\toserver\insertneed\test\addphoto.php on line 62

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <pre> <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <style><img> <br> <blockquote>
  • Lines and paragraphs break automatically.
  • You may insert videos with [video:URL]

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image. is a free online community for webdevelopers and beginners. Anybody can share their code, articles, tips, tutorials, code-examples or other webdesign related material on the site. Newbies can submit their questions and reply to existing questions. CW does not guarantee or warrant reliability of code, data and information published on the site. Use the site on your own risk. The site takes no responsibility of direct or indirect loss or any kind of harm to its users. The site also doesn't take responsibility of infected files or source code with any kind of infection or viruses, worms, spywares, malwares, trojan horses. CW reserves the right to edit, move, or delete any of content for any reason.