# thinkphp-aliyun-oss **Repository Path**: flywit/thinkphp-aliyun-oss ## Basic Information - **Project Name**: thinkphp-aliyun-oss - **Description**: thinkphp 阿里云 oss filesystem - **Primary Language**: PHP - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2023-06-22 - **Last Updated**: 2023-06-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # thinkphp6 阿里云oss 基于 [xxtime/flysystem-aliyun-oss](https://github.com/xxtime/flysystem-aliyun-oss) 轻度封装tp ## 安装 --- ```shell composer require death_satan/thinkphp-aliyun-oss ``` --- ## 初始化 ### 修改配置 *config/filesystem.php* 文件 --- ```php env('filesystem.driver', 'local'), // 磁盘列表 'disks' => [ 'local' => [ 'type' => 'local', 'root' => app()->getRuntimePath() . 'storage', ], 'public' => [ // 磁盘类型 'type' => 'local', // 磁盘路径 'root' => app()->getRootPath() . 'public/storage', // 磁盘路径对应的外部URL路径 'url' => '/storage', // 可见性 'visibility' => 'public', ], //新增一个阿里云磁盘 'aliyun'=>[ 'type'=>'Aliyun',//驱动使用阿里云 'accessId' => '', 'accessSecret' => '', 'bucket' => '', 'endpoint' => '', // 'timeout' => 3600, // 'connectTimeout' => 10, // 'isCName' => false, // 'token' => '', ] // 更多的磁盘配置信息 ], ]; ``` --- ## 使用方法 ### 通过filesystem使用 --- ```php //通过门面使用 think\facade\Filesystem::disk('aliyun') //在控制器中通过注入使用 class TestControl{ public function Test(\think\Filesystem $filesystem) { $aliyun = $filesystem->disk('aliyun'); } } ``` --- ### 文件上传 ```php file('image'); //通过filesystem进行上传 $url = Filesystem::disk('aliyun')->putFile('images', $file); if (!$url) new \exception('上传失败'); dd('上传成功,文件位置:' . $url); } } ```