tjodolv Posted September 25, 2007 Share Posted September 25, 2007 It's me, again... This problem may be a server problem, but I'll start by asking here. I have written a script for uploading images. When i attempt to upload images with a certain filesize, i get a fatal error. I tried with different filesizes, and narrowed down the approximate borderline to between 30k and 40k. A 76K .jpeg file works fine. A 1.7M .jpeg gives the error: Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 2608 bytes) in /Users/test/Sites/cms/lib/functions.inc.php on line 1050 A 20K .png file works fine. A 40K .png file gives the error: Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 3686400 bytes) in /Users/test/Sites/cms/lib/functions.inc.php on line 1056 The line in question is part of a function i found on the web: <?php // this function originally found at http://www.findmotive.com - a wee bit modified function cropImage($nw, $nh, $source, $stype, $dest) { $size = getimagesize($source); $w = $size[0]; $h = $size[1]; switch($stype) { case 'image/gif': $simg = imagecreatefromgif($source); break; case 'image/jpeg': $simg = imagecreatefromjpeg($source); // this is line 1050 break; case 'image/pjpeg': $simg = imagecreatefromjpeg($source); break; case 'image/png': $simg = imagecreatefrompng($source); // this is line 1056 break; } $dimg = imagecreatetruecolor($nw, $nh); $wm = $w/$nw; $hm = $h/$nh; $h_height = $nh/2; $w_height = $nw/2; if($wm> $hm) { $adjusted_width = $w / $hm; $half_width = $adjusted_width / 2; $int_width = $half_width - $w_height; imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h); } elseif(($wm <$hm) || ($wm == $hm)) { $adjusted_height = $h / $wm; $half_height = $adjusted_height / 2; $int_height = $half_height - $h_height; imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h); } else { imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h); } imagejpeg($dimg,$dest,100); return true; } // end cropImage ?> Settings read from phpinfo(): file_uploads On memory_limit 8M post_max_size 32M upload_max_filesize 32M SERVER_SOFTWARE Apache/2.0.59 (Unix) PHP/5.2.3 DAV/2 GD Support enabled GD Version bundled (2.0.34 compatible) What do I need to fix? Link to comment https://forums.phpfreaks.com/topic/70662-solved-memory-problems/ Share on other sites More sharing options...
BlueSkyIS Posted September 25, 2007 Share Posted September 25, 2007 memory_limit 8M Link to comment https://forums.phpfreaks.com/topic/70662-solved-memory-problems/#findComment-355162 Share on other sites More sharing options...
tjodolv Posted September 25, 2007 Author Share Posted September 25, 2007 Ok. But why? 8M is quite a lot more than 1.7M ...? Link to comment https://forums.phpfreaks.com/topic/70662-solved-memory-problems/#findComment-355167 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.