# filesystem **Repository Path**: chleniang/filesystem ## Basic Information - **Project Name**: filesystem - **Description**: 基于flysystem^3.0的,应用于ThinkPHP6的filesystem - **Primary Language**: PHP - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2022-11-01 - **Last Updated**: 2024-09-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: ThinkPHP, tp6, flysystem, FileSystem ## README # TP6/TP8文件存储库 > 基于 `flysystem ^3.0` 的 `filesystem` ## 需求 - php >= 8.0.2 ( league/flysystem ^3.0的要求 ) - topthink/framework ^6.0 | ^8.0 ( 建议使用TP 6.1|8.0 以上, 移除了TP framework自带的filesystem ) - league/flysystem ^3.0 ## 安装、使用 `composer require "chleniang/filesystem"` ```php # 方式一: 直接通过facade类使用 \chleniang\filesystem\facade\Filesystem::disk() # 方式二: 通过注册服务使用 # 可直接添加服务到公共文件 `service.php` 文件中 return [ ... , // 注册的服务名是'file_system',与TP的'filesystem'作以区分 \chleniang\filesystem\Service::class, ]; # 使用服务; app('file_system')->disk() ``` ## 特点 - 支持 `league/flysystem` 完整API 详细请参考 [> flysystem API手册 <](https://flysystem.thephpleague.com/docs/usage/filesystem-api) ```text write($path, $contents, $config) writeStream($path, $stream, $config) read($path) readStream($path) delete($path) deleteDirectory($path) listContents($path, $recursive) fileExists($path) directoryExists($path) has($path) lastModified($path) mimeType($path) fileSize($path) visibility($path) setVisibility($path, $visibility) createDirectory($path, $config) move($source, $destination, $config) copy($source, $destination, $config) ``` - adapter独有API可直接调用 (如果adapter中API与flysystemAPI重名,优先调用flysystemAPI) ```php // 使用方法 \chleniang\filesystem\facade\Filesystem::disk('qiniu')->[adapter独有API...]; // 实现方式 src/Driver.php /** * 除filesystem API 之外,adapter中的方法也可直接调用 * 如果adapter中有与filesystem同名方法,优先调用filesystem中的 */ public function __call($method, $parameters) { if (method_exists($this->filesystem, $method)) { return $this->filesystem->$method(...$parameters); } else { return $this->adapter->$method(...$parameters); } } ``` ## 支持存储类型 > 本库 `chleniang/filesystem` 作为支持 TP 文件存储的基础类库,自身带本地存储 `local` 驱动 > > 其他存储驱动作为独立库存在(没有与本库打包在一起是为了更加灵活,只安装自已需要的) > > 安装其他存储驱动示例: 七牛云 `composer chleniang/filesystem-qiniu` ### 1. 本地存储 > ( 也可直接使用 `topthink/think-filesystem` `2.0` ) - 支持 `ThinkPHP` API - `putFile()` `putFileAs()` - 具体使用请参考 [> TP6手册-上传章节 <](https://www.kancloud.cn/manual/thinkphp6_0/1037639) ### 2. 七牛云 > 请安装 `composer require chleniang/filesystem-qiniu` > > 用法请参考 `chleniang/filesystem-qiniu` [> 使用说明 <](https://gitee.com/chleniang/filesystem-qiniu) ### 3. 阿里云OSS > 请安装 `composer require chleniang/filesystem-aliyun-oss` > > 用法请参考 `chleniang/filesystem-aliyun-oss` [> 使用说明 <](https://gitee.com/chleniang/filesystem-aliyun-oss) ### 4. 其他(待完成) ## Lisence - [Mulan PSL v2](http://license.coscl.org.cn/MulanPSL2)