2

I am getting a memory error:

Fatal error:  Out of memory (allocated 67633152) (tried to allocate 19104 bytes)

I've done a ton of research. I tried to increase memory limit on php.ini to 256M and checked that with phpinfo() to verify it had changed. This did not work.

My image is a big one at 9.6M with 4776px × 2856px res. I know that uploaded images get bloated up to around possibly: 4776x2856x3 = 40M+. But this is well below the memory limit of 256M. I have even tried with a set memory limit of 10000M. This did not work either.

I uploaded other smaller images that worked fine but then retried the big image with no success and no change to error message.

What is my next step?

Here is a slimmed down version of my upload code:

foreach(array_keys($FILES['name']) as $KEY) {

if($FILES['type'][$KEY] === 'image/jpeg') {
    $TEMP = imagecreatefromjpeg($FILES['tmp_name'][$KEY]);
} else if($FILES['type'][$KEY] === 'image/png') {
    $TEMP = imagecreatefrompng($FILES['tmp_name'][$KEY]);
} else if($FILES['type'][$KEY] === 'image/gif') {
    $TEMP = imagecreatefromgif($FILES['tmp_name'][$KEY]);
} else {
    die(); }

$HD = $KEY.'.jpeg';
imagejpeg($TEMP, $HD, 100);

imagedestroy($TEMP); 
}

Here is my php.ini

INPUT:

post_max_size = 1024M
upload_max_filesize = 1024M
max_file_uploads = 200
memory_limit = 1024M
max_execution_time = 259200
max_input_time = 259200
session.gc_maxlifetime = 1200
user3565264
  • 157
  • 2
  • 10
  • Can you limit the max_upload_size? The image libary was not created to handle such large images. – Manuel Arwed Schmidt Feb 21 '15 at 10:07
  • You could also use getimagesize() to determine whether the picture is too memory heavy to pass on to imagecreatefrom*(). See https://stackoverflow.com/questions/6128013/possible-to-check-if-imagecreatefromjpeg-is-going-to-cause-memory-exhausted-fata?rq=1 – Manuel Arwed Schmidt Feb 21 '15 at 10:17
  • I used that and got a number around 54561024. Which is still below my memory limit of 1024M currently set. How do I know its too memory heavy? By using memory limit as a reference? Im not sure what to do anymore with this except for limit users to small images, which is not ideal. – user3565264 Feb 21 '15 at 10:26
  • So it turns out that my hosting package is to blame. phpinfo() != hosting package limits. My RAM is 0.3 GB = 300MB which would probably where the problem lies. Yet 300 MB is still enough for the 60MB that's required. I'm not sure. – user3565264 Feb 21 '15 at 10:41

1 Answers1

-1

Changing memory limit would help in many cases except mine. I just read on my host that even though changing memory limit does reflect in phpinfo(); it is not the real limit imposed by the host which may be different.

Due to resource limits on our Shared Hosting machines, it is not possible to allocate more memory to PHP than the maximum for your package. Using a php.ini file or the memory_limit directive to increase memory for PHP may result in the phpinfo() output reflecting the change however the server will not allocate more memory than the limit imposed

user3565264
  • 157
  • 2
  • 10