Solarpitch Posted November 5, 2007 Share Posted November 5, 2007 Hey, I have the below script that save two uploaded images to the server and creates a thumbnail for each one. The thumbnails create fine but the 2 thumbs are a copy of the second uploaded image and not one of each... etc.. file1.jpg file2.jpg thumb2.jpg thumb2.jpg $folder = "property_images/"; $timest = time(); $image1=""; $image2=""; $image1exists=""; $image2exists=""; $includesimage=""; $image1 = $_FILES['image1']['tmp_name']; $image2 = $_FILES['image2']['tmp_name']; if($image1 != ""){$image1exists = 1; } if($image1exists == 1){$image1file = $folder.$timest."AA".basename($_FILES['image1']['name']);} if($image1exists == 1){$image1 = $folder.$timest."AA".basename($_FILES['image1']['name']);} if($image2 != ""){$image2exists = 1; } if($image2exists == 1){$image2file = $folder.$timest."AA".basename($_FILES['image2']['name']);} if($image2exists == 1){$image2 = $folder.$timest."AA".basename($_FILES['image2']['name']);} if($_FILES['image1']['tmp_name'] != ""){ list($width, $height, $type, $attr) = getimagesize($_FILES['image1']['tmp_name']); move_uploaded_file($_FILES['image1']['tmp_name'], $image1file); $copy1 = $image1file; $destination_width = 120; $destination_height = 120; $imagecop1 = new hft_image($copy1); $sz=getimagesize($copy1); $imagecop1->resize($destination_width, $destination_height, '-'); $image1_thumb = $folder.$timest."THUMB.jpg"; $imagecop1->output_resized($image1_thumb, "JPEG"); } if($_FILES['image2']['tmp_name'] != ""){ list($width, $height, $type, $attr) = getimagesize($_FILES['image2']['tmp_name']); move_uploaded_file($_FILES['image2']['tmp_name'], $image2file); $copy2 = $image2file; $destination_width = 120; $destination_height = 120; $imagecop2 = new hft_image($copy2); $sz=getimagesize($copy2); $imagecop2->resize($destination_width, $destination_height, '-'); $image2_thumb = $folder.$timest."THUMB.jpg"; $imagecop2->output_resized($image2_thumb, "JPEG"); } Can you see anything causing this? Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted November 5, 2007 Share Posted November 5, 2007 You simply overwrite the first image with your second image because you (yeah overwrite it) use the same path and filename: <?php //Some name parameters you define once and for all at the start of your script $folder = "property_images/"; $timest = time(); //Creation of first image $image1_thumb = $folder.$timest."THUMB.jpg"; $imagecop1->output_resized($image1_thumb, "JPEG"); //Creation of second image $image2_thumb = $folder.$timest."THUMB.jpg"; $imagecop2->output_resized($image2_thumb, "JPEG"); ?> You need to make two individual names if you want to store them in the same path. Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted November 5, 2007 Author Share Posted November 5, 2007 Hi, I am just not quite sure what you mean by "You need to make two individual names if you want to store them in the same path." I tried something like this... but it doesnt see to work $image1_thumb = "AA".$folder.$timest."THUMB.jpg"; $image2_thumb = "BB".$folder.$timest."THUMB.jpg"; Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted November 5, 2007 Author Share Posted November 5, 2007 Forget that last post... This should work $image1_thumb = $folder.$timest."AA"."THUMB.jpg"; $image2_thumb = $folder.$timest."BB"."THUMB.jpg"; Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted November 5, 2007 Share Posted November 5, 2007 You can't have to files named THUMB.jpg in the same folder and since you can't the first THUMB.jeg (image1) will simply be overwritten when you output it again (image2). Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted November 5, 2007 Author Share Posted November 5, 2007 Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.