/    Sign up×
Community /Pin to ProfileBookmark

Cannot display uploaded images

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);
?>
[/code]

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

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@bokehJun 13.2006 — The problem I get is that in some images that I upload it displays a black square instead of the image.[/QUOTE]Your code will do this if the image is palette or contains an alpha channel, neither of which apply to jpeg images. Are you always working on jpegs? Have you got a test image that is causing this problem?
Copy linkTweet thisAlerts:
@xeniaauthorJun 13.2006 — Yes I am always uploding jpg images.

When I am uploading the images,in some images it displays normally and others it displays them black squares.
Copy linkTweet thisAlerts:
@bokehJun 13.2006 — [B]Have you got a test image that is causing this problem?[/B][/QUOTE]???
Copy linkTweet thisAlerts:
@xeniaauthorJun 13.2006 — Yes I have testing images.Some of them it uploads them correctly ,some others is just displays black square.
Copy linkTweet thisAlerts:
@bathurst_guyJun 13.2006 — [I]Psst, I think bokeh would like one of the images to test it to see why the "black square problem" is occouring[/I]
Copy linkTweet thisAlerts:
@xeniaauthorJun 15.2006 — I found the problem as I increase the MAX_FILE_SIZE

amd now is working.

<input name="MAX_FILE_SIZE" type="hidden" value="400000">
Copy linkTweet thisAlerts:
@bathurst_guyJun 15.2006 — You should be testing that the size is small enough and display and error/warning
Copy linkTweet thisAlerts:
@xeniaauthorJun 15.2006 — Could you tell me how I can do that please?

Thanks,

Xenia
Copy linkTweet thisAlerts:
@bokehJun 15.2006 — [code=php]if($_FILES['image']['error'])
{
die('File uploading error');
}[/code]
×

Success!

Help @xenia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...