Home  >  Article  >  php教程  >  自定义缓存,自动创建文件夹无权限

自定义缓存,自动创建文件夹无权限

WBOY
WBOYOriginal
2016-06-07 11:45:131397browse

linux系统,nginx+php
使用缓存功能的时候手动指定temp目录,结果自动创建的缓存目录权限为0
ThinkPHP\Lib\Driver\Cache\CacheFile.class.php
中看到:/**<br>      * 初始化检查<br>      * @access private<br>      * @return boolen<br>      */<br>     private function init() {<br>         $stat = stat($this->options['temp']);<br>         $dir_perms = $stat['mode'] & 0007777; // Get the permission bits.<br>         $file_perms = $dir_perms & 0000666; // Remove execute bits for files.<br> <br>         // 创建项目缓存目录<br>         if (!is_dir($this->options['temp'])) {<br>             if (!  mkdir($this->options['temp']))<br>                 return false;<br>              chmod($this->options['temp'], $dir_perms);<br>         }<br>     }看到初始化的时候先
$stat = stat($this->options['temp']);
$dir_perms = $stat['mode'] & 0007777; // Get the permission bits.
先获取inode保护模式值,再跟0007777做位运算,得到最终的权限。
但是我发现,如果目录不存在,这样计算最终得到的结果是0
下面再chmod改变目录权限为0,这样就没有读取,写入权限了。
临时解决办法:
chmod($this->options['temp'], 0777);

AD:真正免费,域名+虚机+企业邮箱=0元

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn