Código :
<? if(isset($_POST['submit'])){ //here we set what file types we want to accept //specifying only what file extensions you want is a bad idea //it won't check the content type. $acceptedfiletypes = array('image/jpeg', 'image/gif', 'image/png', 'image/jpg'); $filetype = $_FILES['srcimage']['type']; //next we check if the file uploaded is in the list above //if not then we set an error if(in_array($filetype, $acceptedfiletypes)){ //find our max size, if none, set one if(round($_POST['maxdimensions']) > 0){ $maxsize = $_POST['maxdimensions']; } else { $maxsize = 100; } //Now we make a unique name for the file //So that they don't overwrite each other. $tmppath = 'C:/xampp/htdocs/Auto/tmp/'; $thumbspath = 'C:/xampp/htdocs/Auto/thumbs/'; $urltothumbs = 'http://localhost/auto/thumbs/'; $filename = strtolower(md5((rand() * time()).$_SERVER['REMOTE_ADDR']).strrchr($_FILES['srcimage']['name'], '.')); //Now that the file has been handled by your webserver //it has been placed in a temporary location //we need to move it to our working directory so we can thumbnail it move_uploaded_file($_FILES['srcimage']['tmp_name'], $tmppath.$filename); //now we make sure that everything is there, just gives us piece of mind if(file_exists($tmppath.$filename)){ //now lets thumbnail it! //This sets our canvas, a jpg, gif or png canvas //depending on what was uploaded switch ($filetype){ case 'image/jpeg': $srcimage = imagecreatefromjpeg($tmppath.$filename); break; case 'image/gif': $srcimage = imagecreatefromgif($tmppath.$filename); break; case 'image/png': $srcimage = imagecreatefrompng($tmppath.$filename); break; case 'image/jpg': $srcimage = imagecreatefrompng($tmppath.$filename); break; default: $srcimage = imagecreatefromjpeg($tmppath.$filename); } //next lets find out the dimensions of the original image //that way we can calculate ratios later on $srcimagex = imagesx($srcimage); $srcimagey = imagesy($srcimage); //next we will see if we need to reduce the height at most //or the width depending which is bigger //Also make sure that the image, either width or height is greater //than the max size, we don't want to imcrease the image size if($srcimagex > $maxsize || $srcimagey > $maxsize){ if($srcimagex > $srcimagey){ $ratio = $maxsize / $srcimagex; } else { $ratio = $maxsize / $srcimagey; } //next calculate the size of the thumbnail $thumbwidth = $srcimagex * $ratio; $thumbheight = $srcimagey * $ratio; } else { $thumbwidth = $srcimagex; $thumbheight = $srcimagey; } //lets create a thumbnail canvas now $thumbnail = imagecreatetruecolor($thumbwidth, $thumbheight); //now lets resize the original to go onto the thumbnail canvas imagecopyresampled($thumbnail, $srcimage, 0, 0, 0, 0, $thumbwidth, $thumbheight, $srcimagex, $srcimagey); $success = imagejpeg($thumbnail, $thumbspath.$filename, 75); //all done so clean up the tmp directory. Big images insane :-o unlink($tmppath.$filename); } } else { //This file was never an image, AND WILL NEVER BE AN IMAGE! echo 'File is not an image! Don\'t waste my time!'; } } ?> <form name="thumbnail" method="post" enctype="multipart/form-data"> File: <input type="file" name="srcimage" /><br /> Max Dimensions: <input type="text" name="maxdimensions" /> (optional)<br /> <input type="submit" name="submit" value="upload" /> </form> <?php //now that it was a success we can link our friends to the image! if($success == true){ ?> <img src="<?php echo 'thumbs/'.$filename; ?>" /><br /> Link: <input type="text" value="<?php echo $urltothumbs.$filename; ?>" /> <? } ?>
En FF me funcionaa muy bien, peroo en IE no me acepta las imagenees, me manda directamente a
Código :
else { //This file was never an image, AND WILL NEVER BE AN IMAGE! echo 'File is not an image! Don\'t waste my time!'; }
al guien sabe cual es el problema q esta ocacionando esto??
