文件或目录权限检查函数
@from web
@access public
@param  string $file_path 文件路径
@return int  返回值的取值范围为{0 <= x <= 15}，每个值表示的含义可由四位二进制数组合推出。
返回值在二进制计数法中，四位由高到低分别代表
可执行rename()函数权限 |可对文件追加内容权限 |可写入文件权限|可读取文件权限。
178744
public static function pathModeInfo(string $file_path): int
    {
        /* 如果不存在，则不可读、不可写、不可改 */
        if (!file_exists($file_path)) {
            return false;
        }

        $mark = 0;

        if (0 === stripos(PHP_OS, 'WIN')) {
            /* 测试文件 */
            $test_file = $file_path . '/cf_test.txt';

            /* 如果是目录 */
            if (is_dir($file_path)) {
                /* 检查目录是否可读 */
                $dir = @opendir($file_path);

                //如果目录打开失败，直接返回目录不可修改、不可写、不可读
                if ($dir === false) {
                    return $mark;
                }

                //目录可读 001，目录不可读 000
                if (@readdir($dir) !== false) {
                    $mark ^= 1;
                }

                @closedir($dir);

                /* 检查目录是否可写 */
                $fp = @fopen($test_file, 'wb');

                //如果目录中的文件创建失败，返回不可写。
                if ($fp === false) {
                    return $mark;
                }

                //目录可写可读 011，目录可写不可读 010
                if (@fwrite($fp, 'directory access testing.') !== false) {
                    $mark ^= 2;
                }

                @fclose($fp);
                @unlink($test_file);

                /* 检查目录是否可修改 */
                $fp = @fopen($test_file, 'ab+');
                if ($fp === false) {
                    return $mark;
                }

                if (@fwrite($fp, "modify test.\r\n") !== false) {
                    $mark ^= 4;
                }

                @fclose($fp);

                /* 检查目录下是否有执行rename()函数的权限 */
                if (@rename($test_file, $test_file) !== false) {
                    $mark ^= 8;
                }

                @unlink($test_file);

                /* 如果是文件 */
            } elseif (is_file($file_path)) {
                /* 以读方式打开 */
                $fp = @fopen($file_path, 'rb');
                if ($fp) {
                    $mark ^= 1; //可读 001
                }

                @fclose($fp);

                /* 试着修改文件 */
                $fp = @fopen($file_path, 'ab+');
                if ($fp && @fwrite($fp, '') !== false) {
                    $mark ^= 6; //可修改可写可读 111，不可修改可写可读011...
                }

                @fclose($fp);

                /* 检查目录下是否有执行rename()函数的权限 */
                if (@rename($test_file, $test_file) !== false) {
                    $mark ^= 8;
                }
            }
        } else {
            if (@is_readable($file_path)) {
                $mark ^= 1;
            }

            if (@is_writable($file_path)) {
                $mark ^= 14;
            }
        }

        return $mark;
    }
849184
protected function getPath($file_name, $path='controller'){
        if($path == "controller"){
            return './app/Http/Controllers/Admin/' . $file_name . '.php';

        } elseif($path == "model"){
            return './app/'.$file_name.'.php';

        } elseif($path == "seed"){
            return './database/seeds/'.$file_name.'.php';

        } elseif($path == "view-index"){
            return './resources/views/admin/'.$file_name.'/index.blade.php';

        } elseif($path == "view-edit"){
            return './resources/views/admin/'.$file_name.'/edit.blade.php';

        } elseif($path == "view-show"){
            return './resources/views/admin/'.$file_name.'/show.blade.php';

        } elseif($path == "view-create"){
            return './resources/views/admin/'.$file_name.'/create.blade.php';

        }
    }
388628
public static function size($path)
    {
        $path = Normalize::diskFullPath($path);

        if (!self::exist($path)) {
            return 0;
        }

        return filesize($path);
    }
980962
public function create($file_path, $content='')
    {
        $file_dir = dirname($file_path);
        $new_path = $file_path;
        if (strstr(PHP_OS, 'WIN')) {
            $file_dir = mb_convert_encoding($file_dir, 'gbk', 'UTF-8');
            $new_path = mb_convert_encoding($file_path, 'gbk', 'UTF-8');
        }
        $this->exists($file_dir) || $this->mkdir($file_dir, 0777);
        // 创建文件
        $status = file_put_contents($new_path, $content, LOCK_EX);
        if ($status === false) {
            throw new Exception('Create '.$file_path.' failed!');
        }
        Log::info('Create '.$file_path.' done!');
    }
96067
def move_file_to_directory(file_path, directory_path):
        
        file_name = os.path.basename(file_path)  # get name of file
        if not os.path.exists(directory_path):
            os.makedirs(directory_path)  # create directory if necessary
        os.rename(file_path, os.path.join(directory_path,
                                          file_name))
1090661
def _get_first_64k_content(file_path):
    

    if not isfile(file_path):
        raise PathDoesNotExistException(file_path)

    file_size = getsize(file_path)

    content_size = min(file_size, 0x10000)

    content = bytearray(content_size)
    with open(file_path, "rb") as file_object:
        content_read = file_object.readinto(content)

        if content_read is None or content_read < content_size:
            raise FileContentReadException(content_size, content_read)

    return content
626872
public function loadExistingStatementsFromCache($file_path)
    {
        $root_cache_directory = Config::getInstance()->getCacheDirectory();

        if (!$root_cache_directory) {
            return;
        }

        $file_cache_key = $this->getParserCacheKey(
            $file_path
        );

        $parser_cache_directory = $root_cache_directory . DIRECTORY_SEPARATOR . self::PARSER_CACHE_DIRECTORY;

        $cache_location = $parser_cache_directory . DIRECTORY_SEPARATOR . $file_cache_key;

        if (is_readable($cache_location)) {
            if ($this->use_igbinary) {
                /** @var array<int, \PhpParser\Node\Stmt> */
                return igbinary_unserialize((string)file_get_contents($cache_location)) ?: null;
            }

            /** @var array<int, \PhpParser\Node\Stmt> */
            return unserialize((string)file_get_contents($cache_location)) ?: null;
        }
    }
177569
public static function getMagicType($file_path) {
		$file_info = finfo_open(FILEINFO_MIME_TYPE);
		$mime_type = finfo_file($file_info, $file_path);
		finfo_close($file_info);

		// Only return valid types, in order to maintain circular compatibility between methods.
		if (static::hasType($mime_type)) {
			return $mime_type;
		}
	}
267172
public function get_file_size($file_path, $clear_stat_cache = false) {
        if(substr($file_path, 0, 5) === 's3://') {
            // for s3 object path
            // you could use this approach only with AWS SDK version >= 3.18.0
            // @see https://github.com/aws/aws-sdk-php/issues/963 for details
            return strval(filesize($file_path));
        } else {
            // for local path (thumbnails e.g.)
            return parent::get_file_size($file_path, $clear_stat_cache);
        }
    }
498365
function (path) {
    if ($bc_$4.pN) {
      var _path = path || ($bc_$4.pN.path.tempDir() + 'tmp.txt');
      return $bc_$4.pN.path.getFileOrDirIconPath(_path)
    }

    return ''
  }
568093
protected function putIntoFile($file_path, $data)
    {
        if ($this->files->isDirectory($this->files->dirname($file_path))) {
            $data = str_replace(["\n", "\r"], '', trim((string) $data));

            return $this->files->put($file_path, $data, $this->use_locking) > 0;
        }

        // @codeCoverageIgnoreStart
        return false;
        // @codeCoverageIgnoreEnd
    }
124339
public static function resolveIncludePath($file_name, $current_directory)
    {
        if (!$current_directory) {
            return $file_name;
        }

        $paths = PATH_SEPARATOR == ':'
            ? preg_split('#(?<!phar):#', get_include_path())
            : explode(PATH_SEPARATOR, get_include_path());

        foreach ($paths as $prefix) {
            $ds = substr($prefix, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR;

            if ($prefix === '.') {
                $prefix = $current_directory;
            }

            $file = $prefix . $ds . $file_name;

            if (file_exists($file)) {
                return $file;
            }
        }

        return null;
    }
289955
public function checkDocument($path = __DIR__) {
        $file = [];
        #需要截取的本地字符串长度
        $leng = strlen($path);
        foreach ($this->file_list['file'] as $key => $value) {
            $name = substr($value, $leng);
            #获取文件唯一码
            $unique = str_replace(DS, "_", $name);
            #获取唯一建
            $key = MD5($unique);
            #获取文件信息
            $file[$key]['code'] = MD5(file_get_contents($value));
            $file[$key]['name'] = $name;
            $file[$key]['time'] = filemtime($value);
        }
        return $file;
    }
109469
public static function size($path)
    {
        $path = ltrim(self::fullpath($path), '/');

        $ch = curl_init('file://' . $path);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_NOBODY, true);

        $headers = curl_exec($ch);
        curl_close($ch);

        $ch = null;

        if (preg_match('#content-length:(\s+?|)(\d+)#i', $headers, $matches)) {
            return $matches[2];
        }

        return false;
    }
41781
protected function get_file_info($relative_path) {
        $fullpath = $this->getFullPath($relative_path);
        $pathInfo = pathinfo($fullpath);
        $filemtime = filemtime($fullpath);

        // check if file is readable
        $is_readable = $this->has_system_permission($fullpath, ['r']);
        // check if file is writable
        $is_writable = $this->has_system_permission($fullpath, ['w']);

        if (is_dir($fullpath)) {
            $model = $this->folder_model;
        } else {
            $model = $this->file_model;
            $model['attributes']['extension'] = isset($pathInfo['extension']) ? $pathInfo['extension'] : '';

            if ($is_readable) {
                $model['attributes']['size'] = $this->get_real_filesize($fullpath);

                if ($this->is_image_file($fullpath)) {
                    if ($model['attributes']['size']) {
                        list($width, $height, $type, $attr) = getimagesize($fullpath);
                    } else {
                        list($width, $height) = [0, 0];
                    }

                    $model['attributes']['width'] = $width;
                    $model['attributes']['height'] = $height;
                }
            }
        }

        $model['id'] = $relative_path;
        $model['attributes']['name'] = $pathInfo['basename'];
        $model['attributes']['path'] = $this->getDynamicPath($fullpath);
        $model['attributes']['readable'] = (int) $is_readable;
        $model['attributes']['writable'] = (int) $is_writable;
        $model['attributes']['timestamp'] = $filemtime;
        $model['attributes']['modified'] = $this->formatDate($filemtime);
        //$model['attributes']['created'] = $model['attributes']['modified']; // PHP cannot get create timestamp
        return $model;
    }
1060328
protected function getPathFile($config_name, $file_name, $file_suffix = '', $extra_dir = '', $format_psr4 = null)
    {
        $format_psr4 = $format_psr4 === null ? false : (bool) $format_psr4;
        $prefix_ns = "";

        if (!$format_psr4) {
            $prefix_ns = str_replace('\\', '/', trim($this->prefix_ns, '\\'));
        }

        $elements =
            [
                rtrim($this->prefix_dir, '/'),
                $prefix_ns,
                Inflector::studlyCaps($config_name),
                Inflector::studlyCaps(sprintf("%s_schema", $this->schema)),
                $extra_dir,
                sprintf("%s%s.php", Inflector::studlyCaps($file_name), $file_suffix)
            ];

        return join('/', array_filter($elements, function ($val) { return $val != null; }));
    }
365377
def _get_file_name(file_path):
    

    file_name = basename(file_path)

    utf8_file_name = bytearray(file_name, "utf8")
    utf8_file_name.append(0)

    return utf8_file_name