php - 文件权限和 CHMOD : How to set 777 in PHP upon file creation?

标签 php file file-permissions chmod

保存文件时有关文件权限的问题,当文件不存在时,最初创建为新文件。

现在,一切顺利,保存的文件似乎具有 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;
}

最佳答案

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

关于php - 文件权限和 CHMOD : How to set 777 in PHP upon file creation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6433643/

相关文章:

php - 如何使用 php 和 mysql 在 bootstrap div 中显示图像

file - 找不到另一个类文件的符号

java - 这段代码什么时候崩溃?

perl - SQLite 数据库文件可以设为只读吗?

Linux - 更改除 1 个目录之外的所有文件和目录的权限?

时间:2019-05-17 标签:c#wcf文件和文件夹浏览器

php - 使 PHP 的 mail() 异步

php - 检查函数是否需要参数

php - 存储复选框数据

android - file.delete() 不工作