siwelis Posted May 11, 2007 Share Posted May 11, 2007 Using the GD Library, I'm trying to upload an image (but set to a MAX size), then copy that image and make a thumbnail set to a max size as well... I'm not sure what I'm doing wrong. Any suggestions? //start testing phase PHP script //using "SELECT OPTION" drop down list on form //determine file type for proper image resizing if ($_POST['file_type'] == "JPG"){ echo "File Type was JPG"; $filetype = "JPG"; } elseif ($_POST['file_type'] == "GIF"){ echo "File Type was GIF"; $filetype = "GIF"; } elseif ($_POST['file_type'] == "PNG"){ echo "File Type was PNG"; $filetype = "PNG"; } //so "$srce1" BELOW knows what type of file to create if ($filetype == JPG){ $createimage = imagecreatefromjpeg; } elseif ($filetype == GIF){ $createimage = imagecreatefromgif; } elseif ($filetype == PNG){ $createimage = imagecreatefrompng; } // This is the temporary file created by PHP $uploadedfile = $_FILES['article_img']['tmp_name']; // Create an Image from it so we can do the resize $srce1 = $createimage($uploadedfile); // Get image original size list($width,$height)=getimagesize($uploadedfile); // set image height/width $newwidth=600; $newheight=($height/$width)*600; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$srce1,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $filename = $_SERVER['DOCUMENT_ROOT']."images/". $_FILES['article_img']['name']; imagejpeg($tmp,$filename,100); imagedestroy($srce1); imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request // has completed. //end testing phase php script //all code below here works //determine folder to upload images to and also //post in SQL column "article_photo" the image location on server $target_path = "/".images."/".$_POST['cat_id']."/"; $target_path = $_SERVER['DOCUMENT_ROOT'].$target_path . basename( $_FILES['article_img']['name']); if(move_uploaded_file($_FILES['article_img']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['article_img']['name']). " has been uploaded"; $folder = "http://www.chexed.com/images/".$_POST['cat_id']."/".$_FILES['article_img']['name']; } else{ //Give instruction in case image not uploaded echo "No Image File was uploaded."; $folder = "0"; } Link to comment https://forums.phpfreaks.com/topic/50970-trying-to-specify-max-size-and-upload-thumbnail-along-the-way/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.