问题描述
|
保存文件时文件权限有关的问题,当文件不存在时,最初会被创建为新文件。
现在,一切顺利,并且保存的文件似乎处于模式“ 0”。
为了使文件另存为“ 1”模式,我必须在此处更改什么?
感谢您提供的任何提示,线索或答案。我认为与之相关的代码包括:
/* write to file */
self::writeFileContent($path,$value);
/* Write content to file
* @param string $file Save content to wich 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;
}
解决方法
PHP有一个内置的功能称为
bool chmod(string $filename,int $mode )
http://php.net/function.chmod
private function writeFileContent($file,$content){
$fp = fopen($file,\'w\');
fwrite($fp,$content);
fclose($fp);
chmod($file,0777); //changed to add the zero
return true;
}
, 您只需要使用chmod()
手动设置所需的权限:
private function writeFileContent($file,$content);
fclose($fp);
// Set perms with chmod()
chmod($file,0777);
return true;
}
, 如果要更改现有文件的权限,请使用chmod(更改模式):
$itWorked = chmod (\"/yourdir/yourfile\",0777);
如果您希望所有新文件都具有特定权限,则需要研究设置umode
。这是一个将默认修改应用于标准模式的过程设置。
这是一个减法。就是说,我的意思是umode
10ѭ会给您默认权限755
(777 - 022 = 755
)。
但是您应该仔细考虑这两个选项。使用该模式创建的文件将完全不受更改保护。