You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel大文件上传异常排查:1GB以上文件上传失败无报错

Hey there, let's figure out why those 1GB+ file uploads are failing on you—even after tweaking your php.ini and .htaccess settings. Here are the most common issues to check, step by step:

1. PHP Execution & Input Time Limits

Large file uploads take way longer than small ones, and PHP's default time limits are probably too strict to handle them. For example, if your upload speed is 10MB/s, a 1GB file would take over 100 seconds to transfer—way beyond the typical 30-second default limits.

  • Update these values in your php.ini:
    max_execution_time = 600 ; 10 minutes, adjust based on your bandwidth
    max_input_time = 600
    
  • Or add these lines to your .htaccess if you can't edit the main php.ini:
    php_value max_execution_time 600
    php_value max_input_time 600
    

2. PHP Memory Limit

Processing large uploads requires more server memory than PHP usually allocates by default. If the memory limit is too low, the upload script will crash silently before finishing.

  • Raise the limit in php.ini:
    memory_limit = 512M ; Or 1024M if your server can handle it
    
  • Or add this to .htaccess:
    php_value memory_limit 512M
    

3. Web Server-Specific Limits

You added client_max_body_size to .htaccess, but that's actually an Nginx setting—it won't work with Apache. Let's fix that based on your server type:

If you're using Apache:

Skip the client_max_body_size line and instead set a request body limit in .htaccess:

LimitRequestBody 2147483648 ; 2GB in bytes (1GB = 1073741824 bytes)

If you're using Nginx:

.htaccess files don't work with Nginx, so you need to edit your site's Nginx config file (usually in /etc/nginx/sites-available/your-site.conf). Add this line inside the server block:

client_max_body_size 2G;

Then restart Nginx to apply changes:

sudo systemctl restart nginx

4. Missing Chunked Upload Logic

Many servers and default upload scripts struggle with single large file transfers, even with all limits raised. If your current setup sends the entire 1GB file in one go, it might get interrupted mid-transfer.

  • Consider switching to chunked uploads: split the file into smaller pieces (like 10MB chunks) on the frontend, upload each chunk separately, then merge them on the server. Tools like Dropzone.js or Fine Uploader can handle the frontend work, and you'll need to update your backend script to reassemble the chunks.

5. Server-Side Script Issues

Don't overlook your actual upload handling code—there might be hardcoded limits or hidden errors:

  • Check if your script has a manual file size check (e.g., if ($_FILES['file']['size'] > 104857600) for 100MB) that's overriding your PHP config.
  • Verify the upload directory has enough disk space and correct permissions (the server user needs write access to the folder).
  • Enable PHP error logging to catch hidden issues. Add this to php.ini:
    error_log = /path/to/your/php-error.log
    
    Then check the log file for clues like memory exhaustion or permission errors.

6. Session Timeout

If the upload takes longer than your PHP session's lifetime, the session might expire, causing the script to terminate early.

  • Adjust the session timeout in php.ini:
    session.gc_maxlifetime = 7200 ; 2 hours
    
  • Or set it at the top of your upload script:
    ini_set('session.gc_maxlifetime', 7200);
    

A quick tip: Test with a slightly smaller large file (like 2GB) first, and always check your web server's error logs (Apache's error.log or Nginx's error.log)—they often have the exact reason the upload failed.

内容的提问来源于stack exchange,提问作者Matt B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 06:48:01