Hi,

I have an upload form for images that resizes/crops them on upload and moves them to a specified folder. Works great. Except when I try to upload a very large photo in file size, with that the case I get this error:

Fatal error: Allowed memory size of 26214400 bytes exhausted (tried to allocate 12416 bytes) in /path/to/file/gallery.php on line 381

At that line of the file is this simple line of code:

$simg = imagecreatefromjpeg($source);

Is there something in the php config file that sets a size limit when using the imagecreatefromjpeg function?

I thought maybe it was just over the max upload size allowed by php, but then I uploaded through a form not using the resize/crop script and it worked great.

Any help you may be able to offer would be greatly appreciated!

    Figured it out. For those who may have had this problem. I simply just placed this code at the top of the script:

    ini_set("memory_limit","16M");

    Rather than editing your php config file this simply temporarily changes that field to the specified value. For mine I just used 16M. You may need more, or you may not need that much.

    Anyways, I hope this helps anyone experiencing this problem.

      It's memory size, not file upload size that is the issue. When you do any of the imagecreate type of functions, it creates a bitmap version of the image in memory. Note that this bitmap can require quite a bit more memory than the original image, as there is no compression in a bitmap, whereas image formats such as JPEG and PNG can use much less memory.

      To get around it, you will need to modify the memory_limit setting.

        Yep, I had just figured it out and just beat you to the punch 😉. Thanks for your help anyways, I've marked this thread as resolved.

          Write a Reply...