php chmod() 不改变权限

标签 php permissions file-permissions chmod writable

我在使用图片上传脚本时遇到问题。

我知道有数百个相同的问题,但我还没有找到适合我的问题。

$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-dataapachehttpd,如果您正在运行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/

相关文章:

php - 如何去除css中的跨浏览器效果

php - 如何使用访问 token 获取 Facebook 用户详细信息

linux - linux/Unix 文件权限中的数字是什么,如 "-rw-rw-r--. 1"

php - HTML Purifier - 转义不允许的标签而不是剥离

php - Laravel-4.1 时间戳()问题

java - 尝试使用 Hive streaming api 建立连接时,hive 暂存目录的权限被拒绝

java - 在 Ubuntu 中构建 Red5 应用程序失败

macos - 如何在多用户 MacOS Sierra 设置上使用 Homebrew

asp.net - 将网站移至新主机导致 "forbidden"