douaoren4402 2011-06-22 00:39
浏览 334
已采纳

文件权限和CHMOD:如何在创建文件时在PHP中设置777?

A question aboud file permissions when saving a file that when non existent, is created initially as new file.

Now, this all goes well, and the saved file appear to have mode 644.

What to I have to change here, in order to make the files save as mode 777?

Thanks a thousand for any hints, clues or answers. The code that I think is relevant here I have included:

/* 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;
}
  • 写回答

3条回答 默认 最新

  • doushenmao9036 2011-06-22 00:41
    关注

    PHP has a built in function called 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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?