Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 40000 bytes) in /mounted-storage/home20a/sub001/sc20063-GJYD/[…] on line 62
It looks like the PHP-script only allowes me to allocate 32 MB to the memory? This was with an example image to test what would happen if a user tries to upload a huge picture.
My question is: How can i predict that this will happen, and then alert the user that the image was too big instead of returning this error? Its a while since I tested it, but I think I tried both try-catch and @, but they both failed since this is a fatal error. The size of the example image is only 1 kB, so it won’t work checking that value.
I think I solved my own problem, I can check the $width and $height of the image, and then notify the user if the image is too big, but I have another question: How do I change the allowed amout of allocated memory? I assume that my users will try to post many high-resolutioned images. I have tried ini_set("memory_limit", $bignumber), but it isn’t working.
To change the
memory_limit, you have to edit thememory_limitdirective in your php.ini file — it can be done in your Apache’s VirtualHost, too, if you don’t want the modification to be effective for your whole server, but only for one website.But you might not always do that — you need to be administrator of your server…
BTW, you can take a look at How to change configuration settings.
Another possibility might be to use imagemagick, and its convert executable, using one of the Program execution Functions. This way, the resizing of your image wouldn’t be done by PHP.
But, here, it means you depend on an external program…