File Permissions and CHMOD: How to set 777 in PHP upon file creation?

前端 未结 3 1651
故里飘歌
故里飘歌 2021-01-11 10:58

A question about 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 h

3条回答
  •  有刺的猬
    2021-01-11 11:36

    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;
    }
    

提交回复
热议问题