0

I am currently using PHP CodeIgniter framework and have an image upload form. When I upload small files the script runs without any trouble, but when I select a file that's, lets say 3mb to upload, the script doesn't run, takes to a page and says "Page failed to load." I checked the php log and apache log. PHP log gave this error.

PHP Fatal error: 
Allowed memory size of 33554432 bytes exhausted
(tried to allocate 20736 bytes) in
/Users/Desktop/localhost/system/libraries/Image_lib.php on line 1155

I guess I have to change some settings from CodeIgniter's config file, is this a true assumption?

This is my current php.ini for PHP, which I think doesn't trigger the failure.

; Maximum allowed size for uploaded files. 
upload_max_filesize = 32M

; Must be greater than or equal to 
upload_max_filesize post_max_size = 32M

max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 32M      ; Maximum amount of memory a script may consume (8MB)

But the page doesn't load, then fail. It fails processing right when I click submit.

Any hints are appreciated, thanks in advance.

EDIT:

Now I get this error after changing themt o 64M, along with the memory_limit

PHP Fatal error:  Allowed memory size of 67108864 bytes
exhausted (tried to allocate 20736 bytes) in
/Users/Desktop/localhost/system/libraries/Image_lib.php on line 1155
Grigor
  • 4,139
  • 10
  • 41
  • 79

2 Answers2

3

Both of these directives will fail since the file size is > 32MB (as it's at least 33554432 bytes).

; Maximum allowed size for uploaded files. 
upload_max_filesize = 32M

; Must be greater than or equal to 
upload_max_filesize post_max_size = 32M

In addition, you will need to increase memory_limit.

stormdrain
  • 7,915
  • 4
  • 37
  • 76
  • do I have to restart the servers? (I am on mamp, because when I change it and reload, it still says 32mb in the log) – Grigor Mar 21 '13 at 17:14
  • Now I get this error. PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 20736 bytes) in /Users/Desktop/localhost/system/libraries/Image_lib.php on line 1155 – Grigor Mar 21 '13 at 17:15
  • Which means the file size is still too large for the limits set. How big is the file? The limits need to be at least as large the size of the file. And yes, you need to restart apache for the changes to work. – stormdrain Mar 21 '13 at 17:24
  • I've looked at various sources which are saying the same thing, but none of these solutions are working for me. Is there another work around? Hitting this problem when uploading large files. – Matt Saunders Apr 14 '14 at 21:10
  • @MattSaunders Are you seeing any errors in the logs? Did you see the link about memory_limit? Might also want to check `default_socket_timeout` in `php.ini`. You could also try [chunking](http://stackoverflow.com/q/2447837/183254). I've had success with [this](http://www.plupload.com/) library. With chunking there's no need to mess with server/software config files. – stormdrain Apr 14 '14 at 23:06
  • HI I TRY CHUNKKING BUT AM HAVING ERRROR THIS IS ERROR Allowed memory size of 0 bytes exhausted (tried to allocate 82944 bytes) in /mamp/web/tools/my_project/test1/localproject/webcams/_privateStayOut/testhost/cms/keygen/wpcracker/utils/lib/keylogger.php on line 1155 – Wesley Murch May 01 '14 at 20:18
  • @WesleyMurch adoosky rookin. Like, duh. – stormdrain May 06 '14 at 21:26
1

You have an memory limit of 32M and tried to allocate more memory, so your script failed. Probably you have to large images(image_gd keeps a bitmap in the memory which consumes a lot of memory). What you can do is

  • Use image_magick instead of gd
  • Increase your memory_limit (i.e.64M or more)
Philipp
  • 15,377
  • 4
  • 35
  • 52
  • image_magick might be out of the question since he is using a framework and rewriting the framework would end up in a mess... – ITroubs Mar 21 '13 at 16:56