Jump to content

weird problem with uploading big images


garydt

Recommended Posts

I've a script that lets users upload jpeg images and then the script resizes them.

 

I've tried uploading an image sized 1.95MB and 2150 pixels wide, it uploads fine. However, when i tried uploading an image sized 1.24MB and 2575 pixels wide i got server error whch i find weird. Anyone know why?

 

My php.ini-

upload_max_filesize: 20M

max_execution_time: 300

memory_limit: 40M

post_max_size: 16M

SMTP: localhost

Link to comment
Share on other sites

  • Replies 92
  • Created
  • Last Reply

Top Posters In This Topic

I've changed the php.ini to

upload_max_filesize: 20M

max_execution_time: 300

memory_limit: 80M

post_max_size: 16M

SMTP: localhost

 

tried uploading a 1.24mb image, 2550pixels wide and got-

 

Error 500 - Internal server error

An internal server error has occured!

Please try again later.

 

Surely, the settings in the php.ini must b high enough??

Link to comment
Share on other sites

Does the script upload and resize without outputting anything to the browser?

 

If it does then I'd be willing to bet that it's not the uploading part that's the problem, but more the resizing part.  Try to echo something to the screen post upload but pre resize and see if it works for both.

 

Are you using the GD library for resizing?  Go here to get an idea of how to calculate the memory usage required...

 

Regards

Huggie

Link to comment
Share on other sites

Thanks, Huggie.

Yes, it must be the resize script as i tried echoing something to the screen before the resizing and it came up.

No, I'm not using the GD library for resizing..

Here's my resizing script-

	function resizeimage($name){
$filename = './uploads/'.$name;
	if(file_exists($filename)) {
		$image		= imagecreatefromjpeg($filename); //unresized image
		$im_info	= getimagesize($filename); //unresized image
		$im_width	= $im_info[0];
		$im_height	= $im_info[1];
		$im_flag	= $im_info[2];

		//max height: 100px; max width: 100px
		if($im_width >= $im_height) {
			$im_divice	= $im_width / 140;
		}else {
			$im_divice	= $im_height / 140;
		}
		$thumb_width	= $im_width / $im_divice;
		$thumb_height	= $im_height / $im_divice;

		//create empty image
		$thumb	= imagecreatetruecolor($thumb_width, $thumb_height);
		//resize image
		imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $im_width, $im_height);

		if(imagejpeg($thumb, "thumbnails/".$name, 80)) { //image-resource, filename, quality
			return 1;
		}

		imagedestroy($thumb); //destroy temporary image-resource
		imagedestroy($image); //destroy temporary image-resource
	}
}

It does work sometimes.  What's wrong with it?

Link to comment
Share on other sites

Perhaps a strange question, but your comments note that you want a maximum thumbnail size of 100x100. However, your code seems to set the longest side to 140px. Was that just an intentional feature change? Looking at the information you posted, you have PHP memory_limit set to 40M, which should be plenty. Are the images coming from two different sources? Can you add some echo statements to echo your assigned values as the script runs? If one of your values resolves to 0, you might be experiencing a divide by zero error.

Link to comment
Share on other sites

Thanks.

I forgot to change comments to 140px

 

The images come from what users upload.

 

I've echoed the assigned values such as $thumb_width and $thumb_height, no value resolves to 0.

 

This is really annoying as it works on smaller images.

What can i do now?

Link to comment
Share on other sites

Here are all the echoed values-

im_width3072
Notice: Use of undefined constant im_height - assumed 'im_height' in C:\Program Files\xampp\htdocs\epeople\uploadform.php on line 104
im_height2304
Notice: Use of undefined constant im_flag - assumed 'im_flag' in C:\Program Files\xampp\htdocs\epeople\uploadform.php on line 105
im_flag2
Notice: Use of undefined constant im_divice - assumed 'im_divice' in C:\Program Files\xampp\htdocs\epeople\uploadform.php on line 109
im_divice21.9428571429
Notice: Use of undefined constant thumb_width - assumed 'thumb_width' in C:\Program Files\xampp\htdocs\epeople\uploadform.php on line 116
thumb_width140
Notice: Use of undefined constant thumb_height - assumed 'thumb_height' in C:\Program Files\xampp\htdocs\epeople\uploadform.php on line 117
thumb_height105

 

How do i check the site logs for any expanded error information?

Link to comment
Share on other sites

Huggie, yes, my mistake.

 

i've increased the Memory_limit to 140M.  When I try uploading an image i see the browser working for 40-50 seconds and then it brings up the page which says the image isn't a jpeg but i know it is. When i try another jpeg it saves it to the server but i get the server error when it tries to resize it. I'm totally confused!

Link to comment
Share on other sites

i opened the image in word (i dont have wordpad), i saw no error.

 

I tried uploading a 442k jpeg, 3500pixels wide. It saved to the server but when it came to resizing the image i got server error 500.

This is my php.ini file now-

upload_max_filesize: 20M

max_execution_time: 300

memory_limit: 300M

post_max_size: 16M

SMTP: localhost

extension=php_gd2.dll

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.