[英]move_uploaded_file gives: failed to open stream: Permission denied
[英]move_uploaded_file gives “failed to open stream: Permission denied ” even with 777
我在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():在第14行的/var/www/html/images/test.jpg中無法將'/ tmp / phps3D2Em'移至'/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.
我通過鍵入以下命令解決了該問題:
sudo chcon -t httpd_sys_rw_content_t /var/www/html/images -R
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.