duandaiqin6080
duandaiqin6080
2013-03-21 16:52

上传大文件时出现PHP致命错误

  • file-upload
  • codeigniter
  • php
已采纳

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
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • duandanai6470 duandanai6470 8年前

    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.

    点赞 评论 复制链接分享
  • dsgoj7457 dsgoj7457 8年前

    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)
    点赞 评论 复制链接分享

为你推荐