Upload jpeg error

Status
Not open for further replies.

smash123

Solid State Member
Messages
15
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!!
 
http://www.php.net/manual/en/function.imagecreatefromjpeg.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...
 
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?
 
csamuels said:
http://www.php.net/manual/en/function.imagecreatefromjpeg.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.
 
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!!
 
Status
Not open for further replies.
Back
Top Bottom