404 Not Found

Not Found

The requested URL /mpr/4.txt was not found on this server.
top5result.com

Extract images from a zip archive

For my second example of using my image thumbnailer I’ve thrown together a little script which accepts a zip archive upload containing images and generates and returns to the browser a new zip archive containing a thumbnail for each image in the original.

Form to upload a zip file containing images

Form to upload a zip file containing images

After processing a new zip is sent to the browser containing thumbnails

After processing a new zip is sent to the browser containing thumbnails


Source code download at the end of this page.

zip2thumb.php

<?php
require_once dirname(__FILE__) . '/paGdThumbnail.php';
 
$thumb_width = 150;
$thumb_height = 150;
$thumb_quality = 75;
$thumb_method = 'crop';
$thumb_bgColour = array(0,0,0);
 
// give us lots of time
set_time_limit(0);
 
// use to store error messages in.
$error = '';
 
$errors = array(
	UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
	UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
	UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded.',
	UPLOAD_ERR_NO_FILE => 'No file was uploaded.',
	UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder.',
	UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.',
	UPLOAD_ERR_EXTENSION => 'File upload stopped by extension.'
);
 
// get url to link to thumbs
$pathinfo = pathinfo($_SERVER['SCRIPT_NAME']);
$download_url = 'http://'.$_SERVER['HTTP_HOST'] . '/' . $pathinfo['dirname'] . '/thumbs.zip';
 
// has the form been submitted?
if( isset($_POST['submit']) ){
 
	// was a file submitted?
	if( isset($_FILES['zip']) ){
		// any errors?
		if( !$_FILES['zip']['error'] ){
			// security check
			if( is_uploaded_file($_FILES['zip']['tmp_name']) ){
				// is it a zip file?
				if( preg_match('#\.zip$#i', $_FILES['zip']['name']) ){
 
					// get the thumbnail options from the form
					$thumb_width = (int)$_POST['thumb_width'];
					$thumb_height = (int)$_POST['thumb_height'];
					$thumb_method = $_POST['thumb_method'];
 
					// create a zip archive object
					$zip = new ZipArchive();
					if( $zip->open($_FILES['zip']['tmp_name']) ){
						$output_name = 'thumbs.zip';
						// create output archive
						$output = new ZipArchive();
						if( $output->open($output_name, ZipArchive::OVERWRITE ) ){
 
							// loop through all the files in the archive
							for( $i = 0; $i < $zip->numFiles; $i++){
								$entry = $zip->statIndex($i);
								// is it an image?	
								if( $entry['size'] > 0 && preg_match('#\.(jpg|gif|png)$#i', $entry['name'] ) ){
									$file = $zip->getFromIndex($i);
									if( $file ){
										$image = imagecreatefromstring($file);
										if( $image ){
											$thumb = paGdThumbnail($image, $thumb_width, $thumb_height, $thumb_method, $thumb_bgColour);
											imagedestroy($image);
											if( $thumb ){
												ob_start();
												imagejpeg($thumb,null,$thumb_quality);
												imagedestroy($thumb);
												$thumb_data = ob_get_clean();
												$output->addFromString(preg_replace('#\.(jpg|gif|png)$#i', '_t.jpg', $entry['name']), $thumb_data);
											}
										}
									}
								}
							}
							$output->close();
						}
						$zip->close();
						header("Location: $download_url");
						exit();
					}
				}
				else{
 
				}
			}
		}
		// display an error message
		else{
			$error = $errors[$_FILES['zip']['error']];
		}
 
	}
 
}
 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Zip to Thumbnails :p</title>
</head>
<body>
	<h2>Upload a zip archive containing images in jpeg, png or gif format.</h2>
	<p>You will receive a zip archive containing a thumbnail for each image in the original archive.</p>
	<p>Select the thumbnail width, height and method using the form below.</p>
<?php if( $error ){ ?>
	<h3 style="color: red;"><?php echo $error?></h3>
<?php } ?>
	<form action="<?php echo $_SERVER['SCRIPT_NAME']?>" method="post" enctype="multipart/form-data">
		<input type="file" name="zip" />
		Width: <input type="text" name="thumb_width" value="<?php echo $thumb_width?>" size="4" />
		Height: <input type="text" name="thumb_width" value="<?php echo $thumb_width?>" size="4" />
		<select name="thumb_method">
			<option value="crop">Crop</option>
			<option value="scale"<?php if( $thumb_method == 'scale' ) echo ' selected="selected" '?>>Scale</option>
		</select>
		<input type="submit" name="submit" value="Create Thumbnails" />
	</form>
</body>
</html>

download

Download: thumbnailer.zip
Version: 1.0
Updated: October 30, 2008
Size: 5.18 KB

Powered by Drain Hole
  • Buy Cheapest cheapest place buy viagra online Online Pharmacy Store. Buy Medications Online.
  • Buy Cheapest free trial of viagra Now 24/Internet)(safe Pharmacy. Best Online.
  • real cialis Online Without Prescription Low Prices. Best Internet.
  • Buy Cheapest cialis alternative Now Online Medical Shop. Free Viagra Pills!
  • Buy Cheap levitra buy Now Discount Pharmacy Online. WorldWide Shipping.
  • Buy Cheap no prescription cheap viagra Now Best Drugstore. Order Cheap Meds Without Rx.
  • Buy Cheapest cialis overdose Online Best Internet. WorldWide Shipping.
  • Buy Cheapest free sample of cialis Now 100% Satisfaction Guaranteed. Best Online.
  • Buy Cheapest cialis in uk online Now Free Viagra Pills! Online Medical Shop.
  • Buy Cheapest buy cheapest viagra Now No Prescription Needed. Best Internet.
  • Buy Cheapest levitra cheap Online 24/Online Pharmacy. Best Internet.
  • Buy Cheapest free cialis trial Now Cheap Pharmacy Online. Best Drugstore.
  • Buy Cheap viagra manufacturer Online WorldWide Shipping. Free Viagra Pills!
  • Buy Cheap viagra blue Now Guaranteed Shipping. 24/Online Pharmacy.
  • Buy Cheapest levitra genaric Now Cheap Pharmacy Online. Free Viagra Pills!
  • Buy Cheap information on levitra Now Free Viagra Pills! Drugs, Health And Beauty.
  • Buy Cheap us based viagra Now WorldWide Shipping. Cheap Online Pharmacy.
  • Buy Cheap side effects of cialis overdose Now WorldWide Shipping. Cheap Pharmacy Online.
  • Buy Cheap viagra patent pfizer Now The Largest Internet Pharmacy. Low Prices.
  • Buy Cheapest cialis for sale Online Discount Drugs At Best Online Drugstore.
  • Buy Cheapest cialis does it work Now Best Drugstore. Drugs, Health And Beauty.
  • Buy Cheap cialis online pharmacy Online Order Cheap Meds Without Rx. Best Online.
  • Buy Cheap cialis dosing Now Cheap Prescription Drugs. Online Medical Shop.
  • Buy Cheapest cialis offers Online Best Internet. Cheap Online Pharmacy.
  • Buy Cheap free generic cialis Now Free Viagra Pills! Guaranteed Shipping.
  • Buy Cheap viagra pharmacy Now Online Medical Shop. Cheap Prescription Drugs.
  • Buy Cheap generic for levitra Online Cheap Online Pharmacy. Best Internet.
  • Buy Cheapest levitra prices Now Discount Pharmacy Online. Pharmacy Store.
  • Buy Cheap cheap cialis pillstore Online 24/Online Pharmacy. Free Viagra Pills!
  • Buy Cheapest viagra cialis compare Online Online Medical Shop. Best Prices.
  • Buy Cheap levitra info Online Cheap Prescription Drugs. Best Drugstore.
  • Buy Cheapest cialis canada online pharmacy viagra Online Best Prices. Pharmacy At The Best Price!
  • Buy Cheap cialis generic rx Now Top Online Pharmacy Supplier. Best Drugstore.
  • Buy Cheap drug cialis Now Cheap Prescription Drugs. Best Drugstore.
  • Buy Cheapest indian cialis pro Now Cheap Online Pharmacy. Best Internet.
  • Buy Cheap cheap female viagra Now Online Medical Shop. No Prescription Needed.
  • Buy Cheap prices cialis 120 Now Best Internet. Discount Pharmacy Online.
  • Buy Cheap cialis prescriptions Now Top Online Pharmacy. Online Medical Shop.
  • Buy Cheap discounted cialis 20 mg Online Best Online. Drugs, Health And Beauty.
  • Buy Cheap levitra take Now Pharmacy Store. Drugs, Health And Beauty.
  • Buy Cheap cialis tablet size Now Best Internet. The Largest Internet Pharmacy.
  • Buy Cheap cialis 30 Now Top Online Pharmacy Supplier. Best Drugstore.
  • Buy Cheapest online generic cialis Now Guaranteed Shipping. Online Medical Shop.
  • Buy Cheap buy cialis in canada Now Cheap Online Pharmacy. Online Medical Shop.
  • Buy Cheapest generic name for cialis Now Pharmacy Store. Online Prices For generic name for cialis!
  • Buy Cheap discount priced viagra Now 24/Online Pharmacy. Top Online Pharmacy.
  • Buy Cheap cialis cheapest online prices Online Cheap Online Pharmacy. Pharmacy Store.
  • Buy Cheap lavitra or viagra Now Drugs, Health And Beauty. Best Drugstore.
  • Buy Cheap viagra superactive Now Cheap Online Pharmacy. Free Viagra Pills!
  • Buy Cheap uk alternative viagra Now Online Prices For uk alternative viagra! Pharmacy Store.
  • Buy Cheapest levitra effects Now Cheap Prescription Drugs. Pharmacy Store.
  • Buy Cheap buy viagra phentermine meridia adipex xenical Now No Prescription Needed For Drugs. Best Prices.
  • Buy Cheap cheap cialis australia Now Top Online Pharmacy. Online Medical Shop.
  • Buy Cheapest blockers and alpha levitra Now Guaranteed Shipping. Pharmacy Store.
  • Buy Cheap generic viagra propecia Now Free Viagra Pills! Online Prices For generic viagra propecia!
  • Buy Cheap viagra online ordering Online Guaranteed Shipping. Free Viagra Pills!
  • Buy Cheapest daily dose cialis availability Online Online Medical Shop. Pharmacy Store.
  • Buy Cheap levitra viagra v cialis Online No Prescription Needed. Best Drugstore.
  • Buy Cheap viagra online canada Now Internet Prices For viagra online canada! Best Online.
  • Buy Cheap viagra 50 mg or 100mg Online Free Viagra Pills! Online Medical Shop.
  • cialis generic Online Without Prescription Online Medical Shop. Low Prices.
  • Buy Cheapest viagra online shop Now Free Viagra Pills! Guaranteed Shipping.
  • Buy Cheapest viagra levitra cialis Now Top Online Pharmacy. Pharmacy Store.
  • Buy Cheapest generic levitra online Online Online Medical Shop. Pharmacy Store.
  • Buy Cheapest levitra and viagra Now Top Online Pharmacy Supplier. Best Online.
  • Buy Cheapest levitra ads Now Low Prices. Internet Prices For levitra ads!
  • Buy Cheap cialis usa Online Online Medical Shop. Cheap Pharmacy Online.
  • Buy Cheapest levitra 10mg Online Top Online Pharmacy. Best Online.
  • viagra generic cheap Online Without Prescription No Prescription Online Pharmacy.
  • Buy Cheap purchase cialis online Now WorldWide Shipping. Buy Medications Online.
  • Buy Cheapest viagra cheep Online Online Medical Shop. Free Viagra Pills!
  • Buy Cheap natural viagra substitute Online Best Online. No Prescription Needed.
  • Buy Cheap professional viagra ceep Now All Medications Are Certificated! Best Online.
  • Buy Cheapest viagra generico impotencia Online Best Online. Internet Prices For viagra generico impotencia!
  • Buy Cheap buy viagra soft Now Best Drugstore. 24/Internet)(safe Pharmacy.
  • Buy Cheap cialis testimonies Now Best Online. Cheap Meds Without Prescription.
  • Buy Cheap find cialis Now Best Internet. Internet Prices For find cialis!
  • Buy Cheapest cheaper viagra Online Top Online Pharmacy. Best Prices.
  • Buy Cheap cialis reaction Now WorldWide Shipping. Cheap Online Pharmacy.
  • Buy Cheapest cheapest price viagra Online Best Online. Cheap Online Pharmacy.
  • Buy Cheap generic cialis price Now Cheap Prescription Drugs. Free Viagra Pills!
  • Buy Cheapest cialis profesional Online Best Drugstore. Top Online Pharmacy.
  • Buy Cheapest cialis cheap overseas Now Best Online. 24/Internet)(safe Pharmacy.
  • Buy Cheap apcalis dysfunction erectile levitra viagra Online Cheap Prescription Drugs. Best Internet.
  • Buy Cheap free viagra canada Now No Prescription Needed For Drugs. Best Online.
  • Buy Cheap what is cialis Now Drugs, Health And Beauty. Free Viagra Pills!
  • Buy Cheapest cialis with viagra Online Best Online. Cheap Prescription Drugs.
  • Buy Cheapest viagra without Now Special Prices For viagra without! Best Prices.
  • Buy Cheap coupon levitra Online Best Drugstore. Discount Online Pharmacy.
  • Buy Cheap overnight shipping of professional cialis Online Discount Pharmacy Online. Best Drugstore.
  • Buy Cheap sex with levitra Now Cheap Prescription Drugs. Online Medical Shop.
  • Buy Cheapest cheap cialis jelly Online Low Prices. Discount Pharmacy Online.
  • Buy Cheap viagra prescription online Online Low Prices. Cheap Prescription Drugs.
  • Buying Cheap cialis cheapest lowest price. Worldwide Rx, Good Prices. WorldWide Shipping.
  • Buy Cheap cialis and high blood pressure Now Online Medical Shop. Buy Medications Online.
  • Buy Cheap viagra levitra cialis pharmacist perscription drugs Online Top Online Pharmacy Supplier. Best Prices.
  • Buy Cheap free levitra sample Online Online Medical Shop. 24/Online Pharmacy.
  • Buy Cheap woman viagra Now Online Medical Shop. Drugs, Health And Beauty.
  • Buy Cheapest viagra mexico Online Best Online. Guaranteed Shipping.
  • Buy Cheapest best price viagra Now Buy Medications Online. Best Online.
  • Scripts.com