PHP chmod()不会更改权限 [英] php chmod() not changing permissions
问题描述
我在图片上传脚本方面遇到问题.
I am having problems with a picture uploading script.
我知道有数百个相同的问题,但是我还没有找到适合我的问题.
I know there are hundreds of the same questions, but I haven't found the one that would be work for me.
$upload_dir = "images/postcards/";
chmod($upload_dir, 777);
if (is_writable($upload_dir)) {
echo 'The file is writable';
} else {
echo 'The file is not writable';
}
这总是返回文件不可写"
This always returns that the file is "not writable"
我尝试将chmod
设置为0777
和-rwxrwxrwx
.但是结果总是一样的.有任何想法吗?
I tried setting chmod
to 0777
and -rwxrwxrwx
. But result was always the same. Any Ideas?
推荐答案
调用脚本的用户必须拥有该目录(如果在Windows中运行脚本,则通常为www-data
,apache
或httpd
) apache/* NIX设置).用户无法在其不拥有的目录上设置777权限.
The directory must be owned by the user invoking the script (typically www-data
, apache
or httpd
if you're running the script in a apache/*NIX setup). A user can't set 777 permissions on directories it doesn't own.
请参阅chmod()上的注释手册:
See the note on the chmod() manual:
当前用户是运行PHP的用户.可能不是 您用于普通Shell或FTP访问的同一用户.该模式可以是 在大多数系统上,仅由拥有文件的用户进行了更改.
The current user is the user under which PHP runs. It is probably not the same user you use for normal shell or FTP access. The mode can be changed only by user who owns the file on most systems.
这篇关于PHP chmod()不会更改权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!