【问题标题】:PHP fatal error when uploading large files上传大文件时出现 PHP 致命错误
【发布时间】:2013-03-21 16:52:04
【问题描述】:

我目前正在使用 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

【问题讨论】:

    标签: php codeigniter file-upload


    【解决方案1】:

    这两个指令都将失败,因为文件大小 > 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

    【讨论】:

    • 我必须重新启动服务器吗? (我在mamp,因为当我更改它并重新加载时,它仍然在日志中显示32mb)
    • 现在我得到这个错误。 PHP 致命错误:第 1155 行 /Users/Desktop/localhost/system/libraries/Image_lib.php 中允许的内存大小为 67108864 字节已用尽(尝试分配 20736 字节)
    • 这意味着文件大小对于设置的限制仍然太大。文件有多大?限制需要至少与文件的大小一样大。是的,您需要重新启动 apache 才能使更改生效。
    • 我查看了各种说法,但这些解决方案都不适合我。还有其他解决方法吗?上传大文件时遇到这个问题。
    • @MattSaunders 您在日志中看到任何错误吗?您是否看到有关 memory_limit 的链接?可能还想在php.ini 中检查default_socket_timeout。你也可以试试chunking。我在this 库上取得了成功。有了分块,就不需要弄乱服务器/软件配置文件了。
    【解决方案2】:

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

    • 使用 image_magick 代替 gd
    • 增加 memory_limit(即 64M 或更多)

    【讨论】:

    • image_magick 可能是不可能的,因为他正在使用框架并且重写框架最终会一团糟......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-30
    • 1970-01-01
    • 2016-04-14
    • 2016-05-17
    • 2016-01-28
    相关资源
    最近更新 更多