Upload multiple images with PHP

<?php

/**
* Smart Image Uploader by @cafewebmaster.com
* Free for private use
* Please support us with donations or backlink
*/


$upload_image_limit = 5; // How many images you want to upload at once?
$upload_dir			= ""; // default script location, use relative or absolute path









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

			$img_type = "";

			### $htmo .= "$k => $v<hr />"; 	### 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 ); 
				$feedback .= "Image and thumbnail created $img_rname<br />";

			}
		}






############################### HTML FORM
	while($i++ < $upload_image_limit){
		$form_img .= '<label>Image '.$i.': </label> <input type="file" name="uplimg'.$i.'"><br />';
	}

	$htmo .= '
		<p>'.$feedback.'</p>
		<form method="post" enctype="multipart/form-data">
			'.$form_img.' <br />
			<input type="submit" value="Upload Images!" style="margin-left: 50px;" />
			Powered by <a href="http://cafewebmaster.com">Cafe Webmaster</a>
		</form>
		';	

	echo $htmo;
AttachmentSize
Download multiple_image_uploader.zip889 bytes

Comments

I like image watertank with

I like image watertank with php.

hi

this was good and simple....
thanks...

I want to add a folder full

I want to add a folder full images with one click and no-javascript and flash. Or at least using one of them but not both. I wonder if this is possible.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Use <pre> all your html php come here </pre> for your code
  • 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

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

CafeWebmaster.com(CW) 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.