qianlizeguo / yii2-mall-storage
There is no license information available for the latest version (dev-master) of this package.
A file uploading extension for Yii2, saving files to object storage service.
dev-master
2019-06-06 09:34 UTC
Requires
- php: >=5.4.0
- aliyuncs/oss-sdk-php: ^2.3
- qcloud/cos-sdk-v5: ^1.0
- qiniu/php-sdk: ^7.2
- yiisoft/yii2: ~2.0.5
This package is not auto-updated.
Last update: 2025-03-08 11:54:05 UTC
README
Usage
-
Firstly, add this lines of code to your Yii application config:
'components' => [ 'class' => 'Hejiang\Storage\Components\StorageComponent', 'basePath' => 'temp/', 'driver' => [ 'class' => 'Hejiang\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('Hejiang\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();
$url
will be a URL string which can access this file on success, orfalse
on failure.If there's any error occurred, these methods will throw a
Hejiang\Storage\Exceptions\StorageException
. Don't forget totry... catch ...
.