我在使用图片上传脚本时遇到问题。
我知道有数百个相同的问题,但我还没有找到适合我的问题。
$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';
}
这总是返回文件“不可写”
我尝试将 chmod
设置为 0777
和 -rwxrwxrwx
。但结果总是一样的。有什么想法吗?
最佳答案
该目录必须由调用脚本的用户拥有(通常是 www-data
、apache
或 httpd
,如果您正在运行apache/*NIX 设置中的脚本)。用户不能对不属于自己的目录设置 777 权限。
请参阅有关 chmod() 的说明 manual :
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() 不改变权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15169684/