Trovato:
Codice PHP:
<?php if(isset($_POST['submit'])) { $msg_errore=""; //make sure this directory is writable! $path_thumbs = "/home/annunci/public_html/Immagini_piccole/"; //the new width of the resized image, in pixels. $img_thumb_width = 200; // $extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed) //List of allowed extensions if extlimit = yes $limitedext = array(".gif",".jpg",".jpeg"); //the image -> variables $file_type = $_FILES['tb_upload_file1']['type']; $file_name = $_FILES['tb_upload_file1']['name']; $file_size = $_FILES['tb_upload_file1']['size']; $file_tmp = $_FILES['tb_upload_file1']['tmp_name']; echo($_FILES['vImage']['size']); //check the file's extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); //uh-oh! the file extension is not allowed! if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { $msg_errore="Gli unici formati ammessi sono .gif .jpg .jpeg"; $nessun_upload = 1; //echo($msg_errore); //exit(); } if($file_size > 1048576) { $msg_errore="La dimensione massima per il file é di 1 MB."; $nessun_upload = 1; } //so, whats the file's extension? $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; //create a random file name $rand_name = md5(time()); $rand_name= rand(0,999999999); //the new width variable $ThumbWidth = $img_thumb_width; ///////////////////////////////// // CREATE THE THUMBNAIL // //////////////////////////////// if(strlen($msg_errore) == 0) { //keep image type if($file_size) { if($file_type == "image/pjpeg" || $file_type == "image/jpeg") { $new_img = imagecreatefromjpeg($file_tmp); } elseif($file_type == "image/x-png" || $file_type == "image/png") { $new_img = imagecreatefrompng($file_tmp); } elseif($file_type == "image/gif") { $new_img = imagecreatefromgif($file_tmp); } //list the width and height and keep the height ratio. list($width, $height) = getimagesize($file_tmp); //calculate the image ratio $imgratio=$width/$height; if ($imgratio>1) { $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; } else { $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; } //function for resize image. if (function_exists(imagecreatetruecolor)) { $resized_img = imagecreatetruecolor($newwidth,$newheight); } else { die("Error: Please make sure you have GD library ver 2+"); } //the resizing is going on here! imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //finally, save the image $i=1; $new_filename = date("Ymd", time())."_".$i.".$file_ext"; while(file_exists('/home/annunci/public_html/Immagini_grandi/'.$new_filename)) { ++$i; $new_filename = date("Ymd", time())."_".$i.".$file_ext"; } while(file_exists('/home/annunci/public_html/Immagini_piccole/'.$new_filename)) { ++$i; $new_filename = date("Ymd", time())."_".$i.".$file_ext"; } echo($new_filename); //ImageJpeg ($resized_img,"$path_thumbs/$rand_name.$file_ext"); ImageJpeg ($resized_img,"$path_thumbs/$new_filename"); ImageDestroy ($resized_img); ImageDestroy ($new_img); } //ok copy the finished file to the thumbnail directory $path_big = "/home/annunci/public_html/Immagini_grandi/"; //move_uploaded_file ($file_tmp, "$path_big/$rand_name.$file_ext"); move_uploaded_file ($file_tmp, "$path_big/$new_filename"); //copy($file_tmp, "$path_big/$new_filename"); } } echo " <form action=\"$_SERVER[PHP_SELF]\" method=\"post\"enctype=\"multipart/form-data\">\n
File:<input type=\"file\" name=\"vImage\" /></p>\n
<input type=\"submit\" name=\"submit\" value=\"Submit\" /></p>"; ?>