【问题标题】:File upload fails laravel文件上传失败 laravel
【发布时间】:2022-08-13 22:45:38
【问题描述】:

所以我创建了简单的表单来上传文件并 dd $request->file

<form 
    action=\"/videos\" 
    method=\"post\" 
    enctype=\"multipart/form-data\"
    id=\"upload_form\"
    name=\"upload_form\"
    >
        @csrf
        <input type=\"file\" name=\"avatar\" />
        <input type=\"submit\" value=\"submit\" />
    </form>

dd($request-&gt;file(\'avatar\');

如果视频大于 1 mb 但小于 8 mb,则会上传错误 1,大小为 0 mb 如果视频大于 8 mb,我会收到错误 Illuminate\\Http\\Exceptions\\PostTooLargeException PHP Warning: POST Content-Length of 21712952 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

这是我在 laravel 中的 php.ini 文件

post_max_size = 100M
; upload_max_filesize = 60M
variables_order = EGPCS
max_execution_time = 3600s
memory_limit = 100M
upload_max_filesize = 60M
  • 你要返回图片吗
  • 如果 .ini 文件生效,您是否与phpinfo() 核对过?

标签: php laravel file-upload


【解决方案1】:

您的 php.ini 配置很好。问题出在 nginx 配置中。

您必须增加client_max_body_size。它的默认值为每个文件1 MB

在您的 nginx 项目的default.conf 中添加以下内容:

server {
    ...

    client_max_body_size 128M;

    ...
} 

【讨论】:

    猜你喜欢
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 2013-06-09
    • 2012-03-18
    相关资源
    最近更新 更多