文件权限和CHMOD:如何在创建文件时在PHP中设置777? [英] File Permissions and CHMOD: How to set 777 in PHP upon file creation?

查看:686
本文介绍了文件权限和CHMOD:如何在创建文件时在PHP中设置777?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当保存一个不存在的文件的时候,一个问题大概是文件权限,最初是作为新文件创建的。



现在,这一切顺利,保存的文件似乎有模式 644



在这里我必须改变什么,为了使文件保存为模式 777



感谢任何提示,线索或答案。我认为在这里的代码我已经包括:

  / *写入文件* / 

self :: writeFileContent($ path,$ value);
$ b $ *将内容写入文件
* @param字符串$ file将内容保存到文件
* @param字符串$ content需要写入文件的字符串
* @return bool
* /

private function writeFileContent($ file,$ content){
$ fp = fopen($ file,'w');
fwrite($ fp,$ content);
fclose($ fp);
返回true;


解决方案

PHP有一个内置函数名为 bool chmod(string $ filename,int $ mode)
$ b http://php.net/function.chmod

  private function writeFileContent($ file,$ content){
$ fp = fopen($ file,'w');
fwrite($ fp,$ content);
fclose($ fp);
chmod($ file,0777); //改为添加零
返回true;
}


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

解决方案

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

这篇关于文件权限和CHMOD:如何在创建文件时在PHP中设置777?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆