Click to See Complete Forum and Search --> : image editing functions - large files...?


gilly914
December 23rd, 2007, 10:31 AM
Hey There,

I created a form for the users to upload images to my site.
I added some functions that edit the files so that they resize them and then save them on to the server, so they won't take up too much space.

The thing is, I'm able to upload every file up to about 200kb.
Above this, and the page gets stuck - I get a browser error.
I checked all the server settings like 'max_input_time', 'post_max_filesize', etc. and everything is ok, and i was even able to upload a 900kb .bmp file, but i can't do the same with .jpg

I added my code to view...
Can anyone help me here...???


// check if the files were really uploaded //
if (isset($_FILES['UserPhoto1']['name']) && is_uploaded_file($UserPhoto1)) {
// UPLOAD & RESIZE THE IMAGES //
// get the image sizes //
list($iwidth, $iheight, $type, $attr) = getimagesize($UserPhoto1);
$fileName1 = time();
if ($type == 2) {
$src_img1 = @imagecreatefromjpeg($UserPhoto1);
$fileName1 .= ".jpg";
} elseif ($type == 3) {
$src_img1 = @imagecreatefrompng($UserPhoto1);
$fileName1 .= ".png";
} elseif ($type == 1) {
$src_img1 = @imagecreatefromgif($UserPhoto1);
$fileName1 .= ".gif";
}

// check if the file needs to be resized //
if ($iwidth > $MaxWidth || $iheight > $MaxHeight) {
$P = $iheight / $iwidth;
if ($iheight > $MaxHeight) {
$NewHeight = $MaxHeight;
$NewWidth = $NewHeight / $P;
}
if ($iwidth > $MaxWidth) {
$NewWidth = $MaxWidth;
$NewHeight = $NewWidth * $P;
}
} else {
$NewWidth = $iwidth;
$NewHeight = $iheight;
}
$TmpImg1 = imagecreatetruecolor($NewWidth, $NewHeight);
imagecopyresized($TmpImg1, $src_img1, 0, 0, 0, 0, $NewWidth, $NewHeight, $iwidth, $iheight);

$NewFileName1 = "../images/customers/".$fileName1;
if ($type == 2) {
@imagejpeg($TmpImg1, $NewFileName1);
} elseif ($type == 3) {
@imagepng($TmpImg1, $NewFileName1);
} elseif ($type == 1) {
@imagegif($TmpImg1, $NewFileName1);
}

$UserFile1 = $NewFileName1;

}

PeejAvery
December 23rd, 2007, 11:33 PM
Can you be more specific about the error message?

Zetas
December 24th, 2007, 02:16 AM
and i was even able to upload a 900kb .bmp file, but i can't do the same with .jpg
Besides the fact that your code doesn't seem to parse .bmp files, i agree with Peej, you'd need to provide the exact browser error your getting and what browser you got it in. As well as the settings for your post_max_size, max_input_time, and upload_max_filesize php.ini variables.

I noticed you said "post_max_filesize" as this is not a valid ini variable, this may be your issue. To quote php.net:

post_max_size integer (http://us2.php.net/manual/en/language.types.integer.php) Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize (http://us2.php.net/manual/en/ini.core.php#ini.upload-max-filesize). If memory limit is enabled by your configure script, memory_limit (http://us2.php.net/manual/en/ini.core.php#ini.memory-limit) also affects file uploading. Generally speaking, memory_limit (http://us2.php.net/manual/en/ini.core.php#ini.memory-limit) should be larger than post_max_size . When an integer (http://us2.php.net/manual/en/language.types.integer.php) is used, the value is measured in bytes. You may also use shorthand notation as described in this FAQ (http://us2.php.net/manual/en/faq.using.php#faq.using.shorthandbytes). If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals (http://us2.php.net/manual/en/language.variables.predefined.php#language.variables.superglobals) are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set. Hope this helps,
Zetas

gilly914
December 24th, 2007, 11:18 AM
I meant to include the upload_max_filesize too..

The problem is that i don;t get any error message. If i did, I would've posted it. When I try uploading a JPEG file larger than 200kb, I don't get any error, and i don;t even get the page back with empty variables.

All I get is the browser error (IE 7) that the page wasn't found...

Any help...????

PeejAvery
December 26th, 2007, 07:40 PM
Have you tried this in any other browsers? IE does have some settings in the registry that can cause reactions such as this.

http://support.microsoft.com/default.aspx?kbid=813827
http://support.microsoft.com/default.aspx?scid=kb;en-us;175500

gilly914
December 28th, 2007, 07:55 AM
Thanks alot PeejAvery,
although i still do not believe that that is the problem.

I think you aren't fully understanding the problem, mostly because i'm not describing it in the best way which is probably a result of a lack of knowledge in some areas of PHP programming on my part...


I will continue searching for the solution myself, and when and if i find it, i'll post it here...

Thanks Again to everyone who tried helping,
Gilly914

PeejAvery
December 28th, 2007, 10:02 AM
Actually, I do understand your problem. But, you didn't answer my question.

The reason for my last post is because some browser (IE based) come with timeouts and post sending limits. Mozilla based browsers leave that to the code. I was wondering if this is the cause of the problem. Hence, I asked you to check other browsers.

If Firefox acts the exact same way, we can go about getting better PHP code for you. If it reacts differently, you know that the problem is IE. Now do you understand my way of going about this?

gilly914
December 30th, 2007, 10:29 AM
Shame on me again!...
Okay, maybe I wasn't fully listening... :) Sorry...

I think your way about going around this might be ok, but after some more testing, I found something out...

I deleted all the image resizing functions, and now i just left a copy function that looks something like this :
copy($_FILES['UserPhoto1']['tmp_name'], $NewFileName1);

And it uploads almost every jpeg file up to 2MB (known server configuration limit)!!!

So now you tell me, can it still be a browser setting???
This leads me to think that this must be some error PHP gets when handling with large image files...

Please correct me if im wrong again!

Thanks Alot, gilly914
:)

PeejAvery
January 1st, 2008, 10:08 PM
In that case, you are correct. It must be in your PHP. Have you tried using move_uploaded_file() to create the file on the server and then work with that as a temp image?