Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 01-23-2006, 11:32 PM   #1 (permalink)
 
Newb Techie

Join Date: Mar 2004

Posts: 13

smash123

Default Upload jpeg error

I have created a page to upload jpg but I got the following error. Everybody knows why?

The error message : Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /home/zeppinra/public_html/web2/admin/product.php on line 145

The following is my source code:
The source code :
$search_new = "select * from product_info order by id desc";
$search_new_query = mysql_query($search_new);
$search_new_row = mysql_fetch_array($search_new_query);
$pic_id = $search_new_row["id"]+1;
$item = $_POST["item"];
$name = $_POST["name"];
$info = $_POST["info"];
$pic = $_FILES["pic"]["name"];
$pic_temp = $_FILES["pic"]["tmp_name"];
$dir = "../pic/";
$pic_link = $pic_id.".jpg";
$move = $dir.$pic_id.".jpg";
move_uploaded_file($pic_temp, $move);
$src_img = imagecreatefromjpeg($move);
if(ImageSX($src_img)>ImageSY($src_img)){
$new_w_s = 250;
$xs = ImageSX($src_img)/250;
$new_h_s = ImageSY($src_img)/$xs;
}else{
$new_h_s = 250;
$xs = ImageSY($src_img)/250;
$new_w_s = ImageSX($src_img)/$xs;
}
(int)($new_w_s);
(int)($new_h_s);
$img = imagecreatetruecolor($new_w_s, $new_h_s);
imagecopyresampled($img, $src_img, 0, 0, 0, 0, $new_w_s, $new_h_s, ImageSX($src_img), ImageSY($src_img));
imagejpeg($img,$move);
imagedestroy($src_img);
imagedestroy($img);
$insert_new = "insert into product_info (item,name,info,pic_link) values ('".$item."','".$name."','".$info."','".$pic_link. "')";
mysql_query($insert_new);

Thanks in advance!!
smash123 is offline  
Old 01-25-2006, 08:28 AM   #2 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,425

office politics will become famous soon enough

Default

http://www.php.net/manual/en/functio...tefromjpeg.php

Under some configurations imagecreatefromjpeg will create files that are owned by the webserver rather than the php user. For example, php may be run as phpuser and the image will be created under apache.

This can lead to permissions problems - only a +0777 will be enough to be able to create a picture.

My solution was to chmod over ftp to 0777 just before the picture is written then change back to 0755 when the image has been created.

The alternative of course would be to have a properly configured system...
office politics is offline  
Old 01-25-2006, 10:54 PM   #3 (permalink)
 
Newb Techie

Join Date: Mar 2004

Posts: 13

smash123

Default

Thank you for you reply, I have already using 777. This lead me to believe there is somehting to mis configured. But I have no idea what should I need to config. ANy idea?
smash123 is offline  
Old 01-26-2006, 05:59 AM   #4 (permalink)
 
Ultra Techie

Join Date: Jul 2005

Posts: 530

TheHeadFL

Send a message via AIM to TheHeadFL
Default

Quote:
Originally posted by csamuels
http://www.php.net/manual/en/functio...tefromjpeg.php

Under some configurations imagecreatefromjpeg will create files that are owned by the webserver rather than the php user. For example, php may be run as phpuser and the image will be created under apache.

This can lead to permissions problems - only a +0777 will be enough to be able to create a picture.

My solution was to chmod over ftp to 0777 just before the picture is written then change back to 0755 when the image has been created.

The alternative of course would be to have a properly configured system...
I don't see how this is relevant when imagecreatefromjpeg does not actually produce any files.

imagecreatefromjpeg() would simply load the jpeg into an image object, which you could manipulate in various ways, and then either output to the stream, or output to a file using imagejpeg()

If it is failing on imagecreatefromjpeg() this tells me that the jpeg is actually never being uploaded at all.

I have actually written a script that uploads JPG images to my server, and it works correctly. Could you post some more of your code so that I can see where you might be going wrong?

To successfully do the job, you need a line like this in your form:

(This line can be repeated as many times as you would like to upload as many files at a time as you would like)
Code:
<input type=file name=img[]>
Then, once the form is submitted, you need to do:
Code:
@copy($img[$i], "$abpath/$img_name[$i]")
Where $i is used to loop through all the images in the array (or just the one) and $abpath refers to the local path on your server where the image is being stored. $img_name[$i] is implicitly created when you specified img[] with type=file. $img_name[] is your filename.

Once you copy this to your local disk, you can do whatever with it. (imagecreatefromjpeg(), etc)

Just so you know it isn't neccesary though. My entire script (except the thumbnails or watermarking portion) does not call imagecreatefromjpeg once.
__________________
Desktop machine: 2 x Opteron 246, Asus K8N-DL, 2GB PC3200 ECC Reg., XFX GeForce 6600GT, 74gb WD Raptor, 2 x 19\" LCDs, Windows XP x64
Server machine: Intel P4 3.0GHz 2MB EM64T, ECS i865pe, 1GB PC3200, 36gb WD Raptor, Windows Server 2003
Laptop: Dell Inspiron 9100 (Intel P4 3.2GHz 1MB Prescott, i865pe, 512MB PC3200, Mobility Radeon 9700, DVD+R/DL Burner), Windows XP
Linux: P3 450Mhz, 386MB ram, Slackware 10.1 (Running mySQL/Apache)
TheHeadFL is offline  
Old 01-26-2006, 11:25 PM   #5 (permalink)
 
Newb Techie

Join Date: Mar 2004

Posts: 13

smash123

Default

TheHeadFL: Thnak you for your reply in detail. Actually, I'm not the one who write the code. He is working the code for me. We are friends. According to him, he said there is something missing in the library (I'm not sure what library) thats why it is showing 'JPEG library reports unrecoverable" he said I need to tell my hosting to install the missing plug in for the library. So I have also forwarded this problem to my hosting and my hosting said there should not have anything missing and tell me the same thing which set 777 for the image dir. Anyway, I will ask my friend to answer your message and post it here soon. Thank you for your time!!
smash123 is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On