ge00rge Posted August 15, 2006 Share Posted August 15, 2006 hi all,I'm using the script below to create thumbnails of uploaded images.The problem is when a file is ~1.5mb I get this error: "Fatal error: Allowed memory size of 29360128 bytes exhausted (tried to allocate 13056 bytes) in /var/www/hosts/mysite/http/imgup.php on line 29" .Is there a filesize limit when using ImagecreatefromXXX?[code]<?php$n_width=100; // Fix the width of the thumb nail images$n_height=100; // Fix the height of the thumb nail imaage$tsrc= "/var/www/hosts/mysite/http/img/" . $HTTP_POST_FILES['userfile']['name']; // Path where thumb nail image will be storedif ($HTTP_POST_FILES['userfile']['type']=="image/gif"){$im=ImageCreateFromGIF($add);$width=ImageSx($im); // Original picture width is stored$height=ImageSy($im); // Original picture height is stored$newimage=imagecreatetruecolor($n_width,$n_height);imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);if (function_exists("imagegif")) {ImageGIF($newimage,$tsrc);}elseif (function_exists("imagejpeg")) {Header("Content-type: image/jpeg");ImageJPEG($newimage,$tsrc);}chmod("$tsrc",0777);}if($HTTP_POST_FILES['userfile']['type']=="image/jpeg"){$im=ImageCreateFromJPEG($add);$width=ImageSx($im); // Original picture width is stored$height=ImageSy($im); // Original picture height is stored$newimage=imagecreatetruecolor($n_width,$n_height);imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);ImageJpeg($newimage,$tsrc);}chmod("$tsrc",0777);?> [/code]($add is specified on another part.)thx Link to comment https://forums.phpfreaks.com/topic/17634-solved-imagecreatefromjpeg-memory-problem/ Share on other sites More sharing options...
DocSeuss Posted August 15, 2006 Share Posted August 15, 2006 php does have a memory limit that can be set in the ini file, it is possible to up this limit on a temp basis with ini_set( "memory_limit", "200M" ) change the memory value to what is appropriate. After the script executes the original value will be restored. Link to comment https://forums.phpfreaks.com/topic/17634-solved-imagecreatefromjpeg-memory-problem/#findComment-75223 Share on other sites More sharing options...
ge00rge Posted August 15, 2006 Author Share Posted August 15, 2006 You're right DocSeuss,the memory_limit is set to 16M,but I don't have access to php.ini to change the limit.I tried using .htaccess file,but it didn't work.Is there any way of "clearing" the memory after the script has finished its work? Link to comment https://forums.phpfreaks.com/topic/17634-solved-imagecreatefromjpeg-memory-problem/#findComment-75250 Share on other sites More sharing options...
DocSeuss Posted August 16, 2006 Share Posted August 16, 2006 ini_set('$variable to change, $value to change to) is a native php function that allows you to change ini variables during the run of the script. The values revert back to the original value after the script with the ini_set() function finishes. Link to comment https://forums.phpfreaks.com/topic/17634-solved-imagecreatefromjpeg-memory-problem/#findComment-75503 Share on other sites More sharing options...
ge00rge Posted August 16, 2006 Author Share Posted August 16, 2006 Ok,I used [code]ini_set( "memory_limit", "200M" );[/code] to change the limit to 200MB,I hope it's not too much!Thanks DocSeuss :) Link to comment https://forums.phpfreaks.com/topic/17634-solved-imagecreatefromjpeg-memory-problem/#findComment-75782 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.