Ankita Gupta
Ankita Gupta

Reputation: 159

Allowed memory size of 67108864 bytes exhausted (tried to allocate 19200 bytes)

I'm trying to upload a image of 10 mb size and it is giving me the error:

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 19200 bytes)

I've also tried to change into .ini file by making changes as:

upload_max_filesize = 70M
post_max_size = 20M

But it still not working... and giving me the same error... its so frustating what can I do next...

What I'm doing wrong with my code, How can I solve this problem?

Upvotes: 3

Views: 17066

Answers (7)

xtianjs
xtianjs

Reputation: 123

You should at least swap the values you have for "post_max_size" (maximum for the entire post) and "upload_max_filesize" (maximum for each actual file)

Upvotes: 0

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385274

Don't read your file into memory. You are using over 64MB in your script which is far more than the 10MB from the image, so you're likely reading the file and copying it around and doing other inefficient stuff. (We can but guess without seeing your code.)

Just copy the file directly from its temporary location into its new desired location with filesystem operations (such as move_uploaded_file).

If you definitely have a need for 64MB for some reason other than merely uploading an image — say, perhaps you're performing complex and costly manipulations on it — then you can change the memory_limit INI option. But this should be a last resort as compared to fixing your code. :)

Upvotes: 3

NikiC
NikiC

Reputation: 101936

You currently have a memory limit of 64M (that's what the message is trying to tell you), which is far bigger than the 10 megabyte image. Probably you have a problem elsewhere (inefficient script, infinite loop, infinite recursion?).

Upvotes: 3

Benjamin Crouzier
Benjamin Crouzier

Reputation: 41925

Correct syntax to use in your php.ini:

memory_limit = 128M

You can also try to change your script to take less memory

Upvotes: 0

renato
renato

Reputation: 125

Please try: ini_set("memory_limit","100M");

Upvotes: 3

Smar
Smar

Reputation: 8611

Your PHP ran out of memory. Instead of raising memory limits, you should seriously think if you could enchant your script so that it takes less memory. For example, instead of reading uploaded file to memory, use only file system actions for it.

Upvotes: 0

Jonnix
Jonnix

Reputation: 4187

It is PHP that is running out of memory. You will need to up the memory_limit option in your php.ini, or use ini_set in your PHP (assuming it is enabled).

Upvotes: 9

Related Questions