barkster Posted May 5, 2008 Share Posted May 5, 2008 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 https://forums.phpfreaks.com/topic/104143-php-upload-memory_limit/ Share on other sites More sharing options...
Fadion Posted May 5, 2008 Share Posted May 5, 2008 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 https://forums.phpfreaks.com/topic/104143-php-upload-memory_limit/#findComment-533222 Share on other sites More sharing options...
rameshfaj Posted May 5, 2008 Share Posted May 5, 2008 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. Link to comment https://forums.phpfreaks.com/topic/104143-php-upload-memory_limit/#findComment-533314 Share on other sites More sharing options...
barkster Posted May 5, 2008 Author Share Posted May 5, 2008 Do you think that because I run this function 2 times in the same script it is causing the memory overload, is there something in the function I should be releasing? Maybe that is what is using up all the RAM? Link to comment https://forums.phpfreaks.com/topic/104143-php-upload-memory_limit/#findComment-533360 Share on other sites More sharing options...
bilis_money Posted May 5, 2008 Share Posted May 5, 2008 yeah trying freeing some memory. maybe it will help. Link to comment https://forums.phpfreaks.com/topic/104143-php-upload-memory_limit/#findComment-533368 Share on other sites More sharing options...
barkster Posted May 5, 2008 Author Share Posted May 5, 2008 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 https://forums.phpfreaks.com/topic/104143-php-upload-memory_limit/#findComment-533385 Share on other sites More sharing options...
Fadion Posted May 5, 2008 Share Posted May 5, 2008 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 https://forums.phpfreaks.com/topic/104143-php-upload-memory_limit/#findComment-533412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.