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

linux系统,nginx+php
使用缓存功能的时候手动指定temp目录,结果自动创建的缓存目录权限为0
ThinkPHP\Lib\Driver\Cache\CacheFile.class.php
中看到:
  1. /**
  2.      * 初始化检查
  3.      * @access private
  4.      * @return boolen
  5.      */
  6.     private function init() {
  7.         $stat = stat($this->options['temp']);
  8.         $dir_perms = $stat['mode'] & 0007777; // Get the permission bits.
  9.         $file_perms = $dir_perms & 0000666; // Remove execute bits for files.

  10.         // 创建项目缓存目录
  11.         if (!is_dir($this->options['temp'])) {
  12.             if (!  mkdir($this->options['temp']))
  13.                 return false;
  14.              chmod($this->options['temp'], $dir_perms);
  15.         }
  16.     }
复制代码
看到初始化的时候先
$stat = stat($this->options['temp']);
$dir_perms = $stat['mode'] & 0007777; // Get the permission bits.
先获取inode保护模式值,再跟0007777做位运算,得到最终的权限。
但是我发现,如果目录不存在,这样计算最终得到的结果是0
下面再chmod改变目录权限为0,这样就没有读取,写入权限了。
临时解决办法:
chmod($this->options['temp'], 0777);

你可能感兴趣的:(PHP)