enoliu / thinkphp-oss
阿里云 OSS 存储的 Thinkphp Flysystem。
1.0.0
2021-01-22 03:21 UTC
Requires
- enoliu/flysystem-oss: ^1.0
- topthink/framework: ^6.0.0
README
阿里云 OSS 存储的 Thinkphp Flysystem..
安装
$ composer require enoliu/thinkphp-oss -vvv
配置
将 oss 配置添加到文件配置 config/filesystem.php
<?php return [ // 默认磁盘 'default' => env('filesystem.driver', 'oss'), // 磁盘列表 'disks' => [ 'local' => [ 'type' => 'local', 'root' => app()->getRuntimePath() . 'storage', ], 'public' => [ // 磁盘类型 'type' => 'local', // 磁盘路径 'root' => app()->getRootPath() . 'public/storage', // 磁盘路径对应的外部URL路径 'url' => '/storage', // 可见性 'visibility' => 'public', ], // 更多的磁盘配置信息 'oss' => [ 'type' => 'oss', 'accessId' => 'LT******JwHf', 'accessSecret' => 'MfSs*******cOzpP', 'bucket' => 'lo***e52', 'endPoint' => 'oss-cn-beijing.aliyuncs.com', // 'timeout' => 3600, // 'connectTimeout' => 10, // 'isCName' => false, // 'token' => '', // 'useSSL' => false // 是否启用ssl ] ], ];
使用方法
<?php namespace app\controller; use app\BaseController; use think\facade\Filesystem; class Upload extends BaseController { public function demo() { $file = $this->request->file('file'); $path1 = Filesystem::putFile('test/path', $file); $path2 = Filesystem::putFileAs('test/path', $file, $file->getOriginalName()); $path3 = Filesystem::disk('oss')->putFile('test/path', $file); // 指定disk驱动 $url1 = Filesystem::getAdapter()->getUrl($path1); $url2 = Filesystem::getAdapter()->getUrl($path2); $url3 = Filesystem::disk('oss')->getAdapter()->getUrl($path3); return compact('path1','url1', 'path2', 'url2', 'path3', 'url3'); } }
响应
{ "path1": "test/path/20210122/56737eece60bd855c78603848edcb10a.json", "url1": "http://lo***e52.oss-cn-beijing.aliyuncs.com/test/path/20210122/56737eece60bd855c78603848edcb10a.json", "path2": "test/path/item.json", "url2": "http://lo***e52.oss-cn-beijing.aliyuncs.com/test/path/item.json", "path3": "test/path/20210122/56737eece60bd855c78603848edcb10a.json", "url3": "http://lo***e52.oss-cn-beijing.aliyuncs.com/test/path/20210122/56737eece60bd855c78603848edcb10a.json" }
更多
use think\facade\Filesystem; $config = [ 'dir' => 'upload/tmp', 'expire' => 60 * 60, 'callback' => 'http://www.baidu.com', 'maxSize' => 10 * 1024 * 1024 ]; array Filesystem::getAdapter()->directUpload($config);
贡献
您可以通过以下三种方式之一进行贡献
代码贡献流程并不非常正式。您只需要确保遵循 PSR-0、PSR-1 和 PSR-2 编码指南。任何新的代码贡献都必须附有适用的单元测试。
许可证
MIT