* Added lower casing the extension check * Added converting spaces in filename to underscores 2000-05-31: * original script released */ include "shared.php"; init(); send_header("Administratie"); if (!$action) { ?> web.blazonry : PHP : Upload and Resize an Image 250) || ($imgsize[1] > 200)) { /*== temp image file -- use "tempnam()" to generate the temp file name. This is done so if multiple people access the script at once they won't ruin each other's temp file ==*/ $tmpimg = tempnam("/tmp", "MKUP"); /*== RESIZE PROCESS 1. decompress jpeg image to pnm file (a raw image type) 2. scale pnm image 3. compress pnm file to jpeg image ==*/ /*== Step 1: djpeg decompresses jpeg to pnm ==*/ system("djpeg $imgfile >$tmpimg"); /*== Steps 2&3: scale image using pnmscale and then pipe into cjpeg to output jpeg file ==*/ system("pnmscale -xy 250 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile"); /*== remove temp image ==*/ unlink($tmpimg); } /*== setup final file location and name ==*/ /*== change spaces to underscores in filename (damn windows!) ==*/ $final_filename = str_replace(" ", "_", $imgfile_name); $newfile = $uploaddir . "/$final_filename"; /*== move file to proper directory ==*/ if (!copy($imgfile,"$newfile")) { /*== if an error occurs the file could not be written, read or possibly does not exist ==*/ print "Error Uploading File."; exit(); } /*== delete the temporary uploaded file ==*/ unlink($imgfile); print(""); /*== DO WHATEVER ELSE YOU WANT SUCH AS INSERT DATA INTO A DATABASE ==*/ } ?>

Upload and Resize an Image

Upload Image:
Click browse to upload a local file