Hello everyone,
I have a very strange problem with uploading and resizing images.
I have developed an e-commerce website that the customers can buy online cloths.I have also created an administrator panel for the admin to insert items in the database uploading also their image. The image of the item will be displayed in three different sizes in the e-commerce site, the enlarge,large and small. The image that the user uploads has the dimension width:310 and from that width I use to make the dimensions of the large and small image.
The code that I am using to upload the image is the following:
[code=php]
<? //copy the image to the server named enlarge_name of image
copy($_FILES[‘image’][‘tmp_name’],”../enlarge_”. $_FILES[‘image’][‘name’]);
?>
<? //make the image large
echo $_POST[‘txt’];
$uploadedfile = $_FILES[‘image’][‘tmp_name’];
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
$newwidth=$width * 0.35 ;
$newheight=$height * 0.35;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename = “../large_”. $_FILES[‘image’][‘name’];
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
?>
<? //make the image small
echo $_POST[‘txt’];
$uploadedfile = $_FILES[‘image’][‘tmp_name’];
$src = imagecreatefromjpeg($uploadedfile);
list($width,$height)=getimagesize($uploadedfile);
$newwidth=36;
$newheight=40;
$tmp=imagecreatetruecolor($newwidth,$newheight);//small
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);//small
$filename = “../small_”. $_FILES[‘image’][‘name’];//small
imagejpeg($tmp,$filename,100);//small
imagedestroy($src);
imagedestroy($tmp);
?>
The problem I get is that in some images that I upload it displays a black square instead of the image.
The strange thing is that some times the same image might display it and the next time it will not.
As I can understand it uploads them in the server but cannot display them correctly.
I have search everywhere and I did a lot of testing to find the problem but I haven’t yet ,so I would be very greatful if you could help me.
Thank you ,
Xenia