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

时间:2013-03-21 16:52:04

标签: php codeigniter file-upload

我目前正在使用PHP CodeIgniter框架并拥有图片上传表单。当我上传小文件时,脚本运行没有任何问题,但是当我选择一个文件时,让我们说3mb上传,脚本不运行,进入页面并说“页面无法加载”。我检查了php日志和apache日志。 PHP日志给出了这个错误。

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

我想我必须从CodeIgniter的配置文件中更改一些设置,这是一个真正的假设吗?

这是我目前用于PHP的php.ini,我认为不会触发失败。

; 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)

但是页面没有加载,然后失败。单击“提交”时,处理失败。

任何提示都表示赞赏,提前谢谢。

修改

现在我将64M更改为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 个答案:

答案 0 :(得分:3)

由于文件大小为>这两个指令都将失败。 32MB(因为它至少为33554432字节)。

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

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

此外,您还需要增加memory_limit

答案 1 :(得分:1)

您的内存限制为32M并尝试分配更多内存,因此您的脚本失败了。可能你需要大图像(image_gd在内存中保留一个占用大量内存的位图)。 你能做的是

  • 使用image_magick代替gd
  • 增加memory_limit(即64M或以上)
相关问题