提问者:小点点

move_uploaded_file提供“打开流失败:权限被拒绝”,即使使用777


在CentOS上使用Apache2.4和PHP7时会出现此错误。

我的文件夹结构如下:

var
  -- www
    -- html
      -- upload.php
      -- uploads
      -- images

当我运行move_uploaded_file($tmpdir,'/var/www/html/uploads')时;-一切都完美无缺。

但是当我试图将目标目录更改为/var/www/html/images时,会出现错误。

警告:move_uploaded_file(/var/www/html/images/test.jpg):无法打开流:在第14行的/var/www/html/UPLOAD.php中拒绝权限

警告:move_uploaded_file():无法将“/tmp/phps3d2em”移动到第14行/var/www/html/upload.php中的“/var/www/html/images/test.jpg”

两个文件夹都具有相同的755模式和相同的所有者(apache)。但不知何故,当我想在图像文件夹上传时,它给了我错误。

我从PHP运行了posix_getuid(),它给了我Apache用户的ID。

问题可能是什么?

编辑:

LS-LH/VAR/www/html结果:

-rw-r--r--.  1  root    root  2.6K Mar 10 13:02 upload.php
drwxr-xr-x.  5  apache  root    23 Mar 12 16:06 images
drwxr-xr-x.  2  apache  root   88K Mar 13 12:36 uploads

httpd-s的结果:

ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main errorLog: "/etc/httpd/logs/error_log"
Mutex authdigest-client: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex default: dir="/run/httpd" mechanism=default
Mutex mpm-accept: using_defaults
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: _RH_HAS_HTTPPROTOCOLOPTIONS
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48

编辑2:我在/var/www/html/perms.php上设置了这个脚本:

print posix_getuid();
$dirs = array_filter(glob('*'), 'is_dir');
foreach( $dirs as $dir ) {
  if ( is_writable($dir) ) print "{$dir} is writable.<br>";
  else print "{$dir} is not writable.";
}

和输出:

48
images is not writable. Permissions may have to be adjusted.
uploads is writable.

共2个答案

匿名用户

我通过键入以下命令解决了此问题:

sudo chcon -t httpd_sys_rw_content_t /var/www/html/images -R

匿名用户

请您分享一下以下方面的成果:

ls -lh /var/www/html

另外,按照https://serverfault.com/a/802350/429496共享apache用户