2017 © Pedro Peláez
 

yii2-extension yii2-cloud-storage

yii2 cloud storage component

image

cdcchen/yii2-cloud-storage

yii2 cloud storage component

  • Thursday, April 28, 2016
  • by cdcchen
  • Repository
  • 1 Watchers
  • 1 Stars
  • 197 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

yii2-cloud-storage 组件使用说明

此组件主要功能为两部分:, (*1)

  • 将目前主流云存储平台的接口封闭,以更加方便的使用。
  • 添加云存储版的UploadFilesaveAs方法将上传文件保存到云存储中。

使用步骤

第一步:在components中添加组件配置

'storage' => [
    'class' => 'cdcchen\yii\cloudstorage\UpYunStorage',
    'isImageBucket' => true,
    'endpoint' => 'v2.api.upyun.com',
    'bucket' => 'test',
    'username' => 'test',
    'password' => '123123',
    'domain' => 'http://test.b0.upaiyun.com',
    'autoGenerateFilename' => true,
    'pathFormat' => '{year}/{month}/{day}',
    'filenameFormat' => '{timestamp}-{uniqid}',
]

第二步:在action中调用storage组件进行文件操作

获取storage组件实例

/* @var \cdcchen\yii\cloudstorage\Storage $storage */
$storage = Yii::$app->get('storage');

云存储文件操作方法说明

上传文件

write方法第一个参数$filename可以接受一个本地文件路径,也可以接受一个文件的内容。, (*2)

若第二个参数为null,则组件会按照pathFormatfilenameFormat的配置来自动生成文件路径及文件名。, (*3)

自动生成文件路径, (*4)

$filename = Yii::getAlias('@runtime/chen.jpg');
$info = $storage->write($filename);

手动指定文件路径, (*5)

$filename = Yii::getAlias('@runtime/chen.jpg');
$filepath = '/test/a.jpg';
$info = $storage->write($filename, $filepath);

返回数据结构如下:, (*6)

图片文件, (*7)

Array
(
    [url] => http://test.b0.upaiyun.com/2016/05/04/1462332949-57296e153ab67.jpeg
    [file] => /avatar/chendong/2016/05/04/1462332949-57296e153ab67.jpeg
    [path] => /avatar/chendong/2016/05/04
    [name] => 1462332949-57296e153ab67.jpeg
    [width] => 479
    [height] => 555
    [type] => JPEG
    [frames] => 1
)

非图片文件, (*8)

Array
(
    [url] => http://test.b0.upaiyun.com/avatar/2016/05/04/1462333056-57296e80bbfa2.doc
    [file] => /avatar/chendong/2016/05/04/1462333056-57296e80bbfa2.doc
    [path] => /avatar/chendong/2016/05/04
    [name] => 1462333056-57296e80bbfa2.doc
)

读取文件(下载文件)

$filename = '/test/a.jpg';
$content = $storage->read($filename);

返回值$content$filename的内容。, (*9)

删除文件

$filename = '/test/a.jpg';
$result = $storage->delete($filename);

删除成功返回true。, (*10)

UploadFile使用说明

cdcchen\yii\cloudstorage\UploadFile继承自yii\web\UploadFile,在此基础上又添加了upload`方法。, (*11)

使用方法同yii\web\UploadFile,如果自动生成文件路径及文件名,直接使用upload方法。这样做是为了保证saveAs的兼容性和一致性。, (*12)

The Versions

28/04 2016

dev-master

9999999-dev https://github.com/cdcchen/yii2-cloud-storage

yii2 cloud storage component

  Sources   Download

BSD-4-Clause

The Requires

 

by Dong Chen

cloud storage yii2 cloud storage

28/04 2016

dev-develop

dev-develop https://github.com/cdcchen/yii2-cloud-storage

yii2 cloud storage component

  Sources   Download

BSD-4-Clause

The Requires

 

by Dong Chen

cloud storage yii2 cloud storage

28/04 2016

1.0.0

1.0.0.0 https://github.com/cdcchen/yii2-cloud-storage

yii2 cloud storage component

  Sources   Download

BSD-4-Clause

The Requires

 

by Dong Chen

cloud storage yii2 cloud storage

28/04 2016

1.0.1

1.0.1.0 https://github.com/cdcchen/yii2-cloud-storage

yii2 cloud storage component

  Sources   Download

BSD-4-Clause

The Requires

 

by Dong Chen

cloud storage yii2 cloud storage

28/04 2016

1.0.2

1.0.2.0 https://github.com/cdcchen/yii2-cloud-storage

yii2 cloud storage component

  Sources   Download

BSD-4-Clause

The Requires

 

by Dong Chen

cloud storage yii2 cloud storage

28/04 2016

1.0.3

1.0.3.0 https://github.com/cdcchen/yii2-cloud-storage

yii2 cloud storage component

  Sources   Download

BSD-4-Clause

The Requires

 

by Dong Chen

cloud storage yii2 cloud storage

28/04 2016

1.0.4

1.0.4.0 https://github.com/cdcchen/yii2-cloud-storage

yii2 cloud storage component

  Sources   Download

BSD-4-Clause

The Requires

 

by Dong Chen

cloud storage yii2 cloud storage