Forum Moderators: coopster

Message Too Old, No Replies

pjpeg-jpeg upload size problem

IE uploads jpegs as pjpegs and bloats them huge

         

deMorte

10:57 am on Sep 4, 2007 (gmt 0)

10+ Year Member



Hello, everybody.

I have a PHP-script that uploads pictures. This picture is then converted to two different pictures (thumbnail and a browsing picture). Problem is that when using IE it converts the image to pjpeg. What happens is that the picture bloats way too big (400 kB picture goes to 1,5 megs).
I check if the picture type is valid (jpeg/pjpeg) and that it is smaller than 600 kB. If the size check is disabled, the image uploads but the size convertion script informs that the memory is overflooded (or something of the like).

Can I change the pjpeg to jpeg somehow? And does this change the size of the file smaller? If it doesn't, I'd like to know can I reduce the size of the pjpeg?
IE is the only browser I have problem with so I'm not too big on rewriting the scripts.

I'll post the relating scripts below:

$type = validImage($_FILES);

if( $type!= FALSE ) {

$target = SITE_DIR."img/residence/image_".$id."/".$imgId.".jpg";
$_FILES['uploaded_file']['tmp_name'];

if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target))
{

$imgLoad = "Image ".basename($FILES['uploaded_file']['name'])." loaded.";
} else {

$imgLoad = "Image Load Failed!";
}

$imgResize = resizeImg( $target, 600, 1, 1, $target);

}
------
function validImage($file) {

if(!strcmp($file['uploaded_file']['type'], "image/jpeg") ) {

if( $file['uploaded_file']['size'] <= MAX_FILE_SIZE ) {

list($img, $type) = split('[/.-]', $file['uploaded_file']['type']);
return TRUE;
}
}
return FALSE;
}
-----


I edited out the thumbnailing function from this script to shorten it a little bit

function resizeImg( $file, $size, $dim, $var, $img_save='' ){

// get image properties to array
$aImgProp = getimagesize($file);

$pic = imagecreatefromjpeg($file);

$height = $aImgProp[1];
$width = $aImgProp[0];

if( $height > 600 ¦¦ $var == 0 ) {

if( $dim == 1 ){
$rel = $width / $height;
$edHeight = $size;
$edWidth = $size * $rel;

} elseif( $dim == 2 ){

$rel = $height / $width;
$edHeight = $size * $rel;
$edWidth = $size;
}

$edImg = imagecreatetruecolor($edWidth, $edHeight);

imagecopyresampled($edImg, $pic, 0, 0, 0, 0, $edWidth+1, $edHeight+1, $width, $height);

imagejpeg($edImg, $img_save);

}
return TRUE;

}

Sorry about the lenghty post.

jatar_k

1:35 pm on Sep 5, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't know your answer but I find this very interesting, this could describe an issue I have been having with a similar upload script.

I have tracked every possible thing I could think of to resolve it, now I have something new I can look for.

Receptional Andy

1:42 pm on Sep 5, 2007 (gmt 0)



I did find one old thread:

[webmasterworld.com...]

Not sure if that's of any use though frankly!

deMorte

1:50 pm on Sep 7, 2007 (gmt 0)

10+ Year Member



I checked the post sent earlier. I have no problem with the pjpeg as such, but the problem is the fact that it makes the file too big to be handled by my resize function.

I am currently just advising everybody using the script not to use IE. Problem is that on later implementations I cannot do that.

If anyone finds out a way to either:
1) Change the file type to jpeg
2) Make the pjpeg file smaller

I'd sure appreciate the help.

deMorte

11:45 am on Sep 27, 2007 (gmt 0)

10+ Year Member



Now the image loading works on IE as well...

And I am quite baffled. I've been basically ignoring this problem ever since it occurred (and it did occur, I'm positive on that) and now it works. I was prepared for exhausting session editing the whole image upload process.

Only thing I did, I added the image/pjpeg to validImage -function. I tried that last time I posted on this thread and it kept complaining that the images are too big (over 600 kB) even when the images were smaller than 200 kBs. Now I tried the image upload on IE with an image size of 520 kBs and it worked.

I'm still advising users not to use IE for uploading images and would like your input on this situation. I've been scouring the web to find someone else complaining about pjpeg-size issues but I haven't found anyone.

Jatar-K had some problem that he/she thought could be caused by the pjpeg-size. I'd like to hear if this was the case.

[edited by: deMorte at 11:51 am (utc) on Sep. 27, 2007]