💾 Flysystem adapter for the oss storage.
- PHP >= 7.0
$ composer require "iidestiny/flysystem-oss" -vvv
use League\Flysystem\Filesystem;
use Iidestiny\Flysystem\Oss\OssAdapter;
use Iidestiny\Flysystem\Oss\Plugins\FileUrl;
$root = ''; // �资源默认根路径,此参数可有可无
$accessKeyId = 'xxxxxx';
$accessKeySecret = 'xxxxxx';
$endpoint= 'oss.iidestiny.com'; // ssl:https://iidestiny.com
$bucket = 'bucket';
$isCName = true; // 如果 isCname 为 false,endpoint 应配置 oss 提供的域名如:`oss-cn-beijing.aliyuncs.com`,cname 或 cdn 请自行到阿里 oss 后台配置并绑定 bucket
$adapter = new OssAdapter($accessKeyId, $accessKeySecret, $endpoint, $bucket, $isCName, $root);
$flysystem = new Filesystem($adapter);
bool $flysystem->write('file.md', 'contents');
bool $flysystem->write('file.md', 'http://httpbin.org/robots.txt', ['options' => ['xxxxx' => 'application/redirect302']]);
bool $flysystem->writeStream('file.md', fopen('path/to/your/local/file.jpg', 'r'));
bool $flysystem->update('file.md', 'new contents');
bool $flysystem->updateStream('file.md', fopen('path/to/your/local/file.jpg', 'r'));
bool $flysystem->rename('foo.md', 'bar.md');
bool $flysystem->copy('foo.md', 'foo2.md');
bool $flysystem->delete('file.md');
bool $flysystem->has('file.md');
string|false $flysystem->read('file.md');
array $flysystem->listContents();
array $flysystem->getMetadata('file.md');
int $flysystem->getSize('file.md');
string $flysystem->getAdapter()->getUrl('file.md');
string $flysystem->getMimetype('file.md');
int $flysystem->getTimestamp('file.md');
use Iidestiny\Flysystem\Oss\Plugins\FileUrl;
use Iidestiny\Flysystem\Oss\Plugins\SignUrl;
use Iidestiny\Flysystem\Oss\Plugins\TemporaryUrl;
use Iidestiny\Flysystem\Oss\Plugins\SignatureConfig;
// 获取 oss 资源访问链接
$flysystem->addPlugin(new FileUrl());
string $flysystem->getUrl('file.md');
// url 访问有效期 & 图片处理「$timeout 为多少秒过期」
$flysystem->addPlugin(new SignUrl());
string $flysystem->signUrl('file.md', $timeout, ['x-oss-process' => 'image/circle,r_100']);
// url 访问有效期「$expiration 为未来时间 2019-05-05 17:50:32」
$flysystem->addPlugin(new TemporaryUrl());
string $flysystem->getTemporaryUrl('file.md', $expiration);
oss 直传有三种方式,当前扩展包使用的是最完整的 服务端签名直传并设置上传回调 方式,扩展包只生成前端页面上传所需的签名参数,前端上传实现可参考 官方文档中的实例 或自行搜索
use Iidestiny\Flysystem\Oss\Plugins\SignatureConfig
$flysystem->addPlugin(new SignatureConfig());
object $flysystem->signatureConfig($prefix, $callBackUrl, $expire);
- Laravel 5:iidestiny/laravel-filesystem-oss