當保存一個文件的時候,文件的權限會被放到一個不存在的地方,最初被創建爲新文件。文件權限和CHMOD:如何在創建文件時在PHP中設置777?
現在,這一切順利,保存的文件似乎有模式644
。
爲了使文件保存爲模式777
,我必須在這裏更改些什麼?
非常感謝任何提示,線索或答案。我認爲的代碼是與此有關我已經包括:
/* 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;
}
請注意,0777模式是**危險**。請參閱http://stackoverflow.com/questions/2338641/in-a-php-apache-linux-context-why-exactly-is-chmod-777-dangerous – 2011-06-22 00:54:27
@Phoenix謝謝。我葡萄牙0766就足夠了(需要允許所有的寫入權限)。那個更好嗎? – Sam
0766更好;這將防止任意代碼執行。該文件是否需要**世界**可寫,或只要例如Apache可以寫入文件就足夠了?你有一組需要能夠寫這些文件的應用程序嗎?如果你讓它們作爲同一組運行並設置0764模式呢? – 2011-06-22 01:05:13