Jump to content

[SOLVED] 2 images being uploaded, only 1 thumbnail showing?


Solarpitch

Recommended Posts

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?

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.

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.