Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

My upload script in PHP has a fatal error with low memory_limit when resizing images. How do I deal with this?

0
Posted

My upload script in PHP has a fatal error with low memory_limit when resizing images. How do I deal with this?

0

Low memory_limit is usually due to how the GD library opens up a JPG in memory to manipulate it. In my best explanation, JPEG is like zip it is only small to cross the wires. When you need to change it using PHP’s GD library it will work on the full image uncompressed in memory. Open up your image in photoshop, look at the ‘document size’ in the photoshop lower left status bar. Lots of those 2-4MB JPEGs are actually 20-25MB uncompressed images and that is how the GD library will use them in memory. Default memory limit is 16M in most php.ini setups but they can be overwritten by .htaccess or the PHP script in most cases with safe mode turned off. Try limiting the image’s uncompressed size by resizing the image and trying again. Then try to capture and deal with that error so you can send something meaningful back to the JavaScript.

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.