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

PHP文件上传报错UPLOAD_ERR_NO_TMP_DIR(错误码6)求助

Fixing UPLOAD_ERR_NO_TMP_DIR (Error Code 6) When Uploading Files

Hey there, let's troubleshoot this upload error step by step. Since you haven't changed any configs and sys_get_temp_dir() correctly returns /tmp, the issue is almost certainly related to filesystem permissions, resource limits, or security restrictions—here's what to check:

1. Verify /tmp Directory Permissions & Ownership

PHP needs write access to the temp directory to store uploaded files temporarily.

  • Log into your server and run this command to check /tmp's status:
    ls -ld /tmp
    
    The output should show permissions drwxrwxrwt (the t is the sticky bit, which is critical for secure temp directory behavior) and owner/group as root:root.
  • If permissions are incorrect, fix them with:
    chmod 1777 /tmp
    
    This sets the standard, secure permissions that allow all users to write to /tmp while preventing unintended file deletion by non-owners.

2. Check if /tmp is Full or Out of Inodes

Even with correct permissions, a full filesystem or exhausted inodes will block new file creation:

  • Check disk space usage for /tmp:
    df -h /tmp
    
  • Check inode usage (each file/directory uses one inode):
    df -i /tmp
    
  • If either is full, clean up old files in /tmp. For example, delete files older than 7 days to free up space:
    find /tmp -type f -mtime +7 -delete
    

3. Check PHP's open_basedir Restriction

The open_basedir setting can limit which directories PHP can access, even if sys_get_temp_dir() returns /tmp:

  • Open your php.ini file (location varies by server—common paths are /etc/php/<version>/fpm/php.ini or /etc/php/<version>/apache2/php.ini).
  • Look for the open_basedir line. If it's set, make sure /tmp is included in the list of allowed directories (e.g., open_basedir = /var/www/html/:/tmp/).
  • Save the file and restart your PHP service (e.g., systemctl restart php8.2-fpm) or web server to apply changes.

4. Check SELinux Policies (For Linux Servers With SELinux Enabled)

SELinux can block web server processes from writing to /tmp even with correct filesystem permissions:

  • Temporarily disable SELinux to test if it's the cause:
    setenforce 0
    
  • Try uploading a file again. If it works, adjust SELinux policies instead of leaving it disabled:
    • For Apache:
      setsebool -P httpd_unified 1
      
    • For Nginx:
      setsebool -P nginx_unified 1
      
    The -P flag makes the change persistent across server reboots.

5. Quick Check: File Size Limits (Just to Rule Out)

While your 91kb file is way below typical limits, it's worth confirming these php.ini settings are set appropriately:

  • upload_max_filesize = 2M (more than enough for your file)
  • post_max_size = 8M (should be larger than upload_max_filesize)
  • Restart PHP/web server after any changes.

After trying these steps, test your file upload again—this should resolve the UPLOAD_ERR_NO_TMP_DIR issue.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 09:04:07