我在使用 PHP 上传文件时不断收到 UPLOAD_ERR_NO_TMP_DIR

I keep getting UPLOAD_ERR_NO_TMP_DIR while uploading file using PHP

我正在尝试使用 PHP 7.0.15.

在我的 Fedora 25(32 位)Apache 服务器上上传文件

我收到 UPLOAD_ERR_NO_TMP_DIR 错误,尽管我已经设置了适当的设置(甚至比我应该设置的更多,但我目前在本地工作)上传目录的权限,我已将目录的所有者更改为 apache。

我正在尝试上传一个 6kB 大的 .docx 文件,我在 php.ini 中的 upload_tmp_dir 设置为 /home/temporary

ls -l returns 代码如下:

drwxrwxrwx.  2 apache root           4096 Feb 11 20:14 temporary

sys_get_tmp_dir() returns 正确路径:/home/temporary

但我仍然得到错误 6

debug outputArray
(
[userfile] => Array
    (
        [name] => rus.docx
        [type] => 
        [tmp_name] => 
        [error] => 6
        [size] => 0
    )
)

什么会导致这个问题?

将临时目录放在/var/www/var/www/html下。

除此操作外,您还需要授予Apache rewrite semanage 权限。

您需要检查 php.ini 中的一些内容。确保你打对了 php.ini:

  • upload_tmp_dir: 这是PHP上传时存放临时文件的目录。
  • open_basedir:限制PHPread/write对指定路径及其子目录的权限操作。 确保 upload_tmp_dir 在此路径内!
  • post_max_size:将其放大以适应您上传的尺寸。
  • upload_max_filesize: 允许的文件大小限制。

如果您想调整 tmp 目录设置,请尝试编辑您选择的 /etc/profile 或 /etc/environment(仅针对当前会话或所有时间),以上检查适用于它。