【发布时间】:2018-08-21 14:42:27
【问题描述】:
我在 CentOS 上使用 Apache 2.4 和 PHP 7 时遇到此错误。
我有这样的文件夹结构:
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”移动到 '/var/www/html/images/test.jpg' 在 /var/www/html/upload.php 第 14 行
两个文件夹具有相同的 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.
【问题讨论】:
-
photos?images?是哪个? -
照片 != 图片
-
抱歉,这是图片。我已经更新了问题。
标签: php apache permissions upload file-permissions