tmzkj-yii2-shop/yii2-shop-storage
Composer 安装命令:
composer require tmzkj-yii2-shop/yii2-shop-storage
包简介
A file uploading extension for Yii2, saving files to object storage service.
README 文档
README
Thanks for your attention. This package is only used for my company projects, please do NOT use it in your product environment.
Usage
-
Firstly, add this lines of code to your Yii application config:
'components' => [ 'class' => 'Tmzkj\Storage\Components\StorageComponent', 'basePath' => 'temp/', 'driver' => [ 'class' => 'Tmzkj\Storage\Drivers\Local', 'accessKey' => '', 'secretKey' => '', 'bucket' => '', ] ]
-
Then after app bootstarpping, you would get the storage component instance like that:
$storage = \Yii::$app->storage;
Alternatively, you can also create a driver while app running:
$storage->setDriver('Tmzkj\Storage\Drivers\Local', []);
-
Fetch uploaded file by field name:
$file = $storage->getUploadedFile('FILE-FIELD-NAME');
-
Save it.
$url = $file->saveAs('NEW-FILE-NAME.EXT'); // or $url = $file->saveWithOriginalExtension('NEW-FILE-BASE-NAME'); // or $url = $file->saveAsUniqueHash();
$urlwill be a URL string which can access this file on success, orfalseon failure.If there's any error occurred, these methods will throw a
Tmzkj\Storage\Exceptions\StorageException. Don't forget totry... catch ....
About
Working at: Zhejiang Tmzkj Technology Co., Ltd.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2023-12-01