views:

53

answers:

3

Any ideas why I'm getting ....

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to

allocate 9792 bytes) in /home/frich/public_html/creation/systemc/sMain/upload_image.php on line 77

on the following line

$oldImage = imagecreatefromjpeg($img);

The php grabs an image from a HTML form and resizes it.

Works perfectly fine if its a small file. I.e. a few hundred KB

Tried with a larger file as I want a max of up to 4mb. The image I get an error with is ca. 2mb

Thanks in advance

+6  A: 

The image you are trying to process is too large for the 32 MB memory limit your script has.

Resizing an image takes up at least

(width in pixels) x (height in pixels) x 3 (or 4)

bytes (1 byte each for Red / Green / Blue, possible one additional byte for transparency)

You need to increase the memory_limit setting on the server, or ask the administrator to do so.

32MB is a pretty decent and common value, though - you may be out of luck if you're on shared hosting.

Alternatively, if possible on your server, use ImageMagick, whose memory consumption does not count toward the memory_limit.

Pekka
Thanks for your help again, was able to add a customer ini file.Cheers
Stevanicus
A: 

Depending on your php configuration you you might be able to increase the memory limit for the script with ini_set(); For example,

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

I've used this on a number of occasions with image processing tasks, although 4mb files are quite a heavy load for a web server.

Monkeyarmada
+2  A: 

You are getting error

"""""""""""""""""""""""" Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to

allocate 9792 bytes) in /home/frich/public_html/creation/systemc/sMain/upload_image.php on line 77 """"""""""""""""""""""""

It shows that either you are using a sheared hosting because your server memory_limit is 32 MB

You need to increase your memory limit as said above by "Pekka" and "MartyIX"

but how you do this there are three ways of doing so.

1st. ask your hosting company to increase your memory limit,

they will increase it upto 48MB max that is the restriction of any hosting company for sheared hosting acount.

2nd. upload a php.ini file

with written "memory_limit = 100M and max_memory = 100M"

you can change 100M to any size that you want but that can be in limit so that it will not use extra resources of server else your account may be suspended by your hosting company

LIMITATION: this option may not work properly on every hosting because some times this code may be blocked by admin so that server resources may be consumed in LIMIT.

3rd upload a ".htaccess"

written inside it "php_value memory_limit 32M"

or

by default it is available in your hosting web directory then you can first download it as it is having other settings too. download it open it with notepad and write "php_value memory_limit 32M"

and

4th option add a PHP code your page

"ini_set('memory_limit', '32M');" (Not tested yet by me, may it work fine)

Thanks and Regards........

Shailender Ahuja
Thanks, my hosting company allowed me to upload a customer php.ini file where the script was being executed and works like a treat now.
Stevanicus
Nice step-by-step list! Would upvote but I'm out of votes for today.
Pekka