Jump to content

PHP Upload memory_limit


barkster

Recommended Posts

I'm writing a simple upload script and  when I upload a 300k file I get "Allowed memory size of 8388608 bytes exhausted (tried to allocate 2048 bytes) in..." when the file is totally under 8MB?  I've used this before and never had to change any setting in ini file or anything.  Seems to fail on "imagecreatefromjpeg" line.

 

function createthumb($filename,$thumb_path_name,$thumbsize) {
list($width, $height) = getimagesize($filename);			
$imgratio=$width/$height;
if ($imgratio>1){
	 $newwidth = $thumbsize;
	 $newheight = $thumbsize/$imgratio;
}else{
	 $newheight = $thumbsize;
	 $newwidth = $thumbsize*$imgratio;
}				
$thumb = imagecreatetruecolor($newwidth,$newheight);
$source = imagecreatefromjpeg($filename);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
if(!imagejpeg($thumb,$thumb_path_name,80)) {
	error_log("\n".date("h:i:s").":Could not create thumbnail: ".$newname,3,"error.txt");
}
}

Link to comment
Share on other sites

It hasnt to do with filesize, but memory (RAM) used. Probably ure running gd functions over very big image files, which drains the allowed memory of 8MB. U can increase the allowed memory in php.ini or with -- ini_set("memory_limit","10M"); -- but that shouldnt be a good practice i guess.

Link to comment
Share on other sites

Yes, that seems to be what it was I modified it to this and uploaded some 2MB images no problem

 

function createthumb($filename,$thumb_path_name,$thumbsize) {
$source = imagecreatefromjpeg($filename);
list($width, $height) = getimagesize($filename);			
$imgratio=$width/$height;
if ($imgratio>1){
	 $newwidth = $thumbsize;
	 $newheight = $thumbsize/$imgratio;
}else{
	 $newheight = $thumbsize;
	 $newwidth = $thumbsize*$imgratio;
}				
$thumb = imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
if(!imagejpeg($thumb,$thumb_path_name,80)) {
	error_log("\n".date("h:i:s").":Could not create thumbnail: ".$newname,3,"error.txt");
}
imagedestroy($source);
imagedestroy($thumb);
}

Link to comment
Share on other sites

U cant always edit the php.ini file and it is not good option to do so.This can be better done in the client side scripting using the JAVASCRIPT.I suggest you to try this.

 

U cant alwyas edit the php.ini and thats true on shared hosts. Anyway they provide custom php.ini and also using ini_set() wont change the default php.ini, only change that feature on the specific script. As for the client side using javascript, i really dont get what ure talking.

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.