当保存一个不存在的文件时,有关文件权限的问题,最初创建为新文件。
现在,一切都很顺利,保存的文件似乎具有模式644
。
为了使文件保存为模式777
,我必须在这里更改什么?
/* write to file */
self::writeFileContent($path, $value);
/* Write content to file
* @param string $file Save content to which file
* @param string $content String that needs to be written to the file
* @return bool
*/
private function writeFileContent($file, $content){
$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
return true;
}
字符串
3条答案
按热度按时间7y4bm7vi1#
PHP有一个内置的函数
bool chmod(string $filename, int $mode )
http://php.net/function.chmod
字符串
aiqt4smr2#
您只需要使用
chmod()
手动设置所需的权限:字符串
irlmq6kh3#
如果您想更改现有文件的权限,请使用chmod(更改模式):
字符串
如果你想让所有的新文件都有一定的权限,你需要设置你的
umode
。这是一个进程设置,它将默认修改应用到标准模式。这是一个减法。我的意思是
022
的umode
将给予您755
(777 - 022 = 755
)的默认权限。但是你应该非常仔细地考虑这两个选项。用这种模式创建的文件将完全不受保护。