PHP code example of dungang / yii2-file-storage

1. Go to this page and download the library: Download dungang/yii2-file-storage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dungang / yii2-file-storage example snippets



Class LocalController extends Controller {
	public function actions(){
		return [
			'init-upload'=>[
				'class'=>'dungang\storage\InitAction'
			],
			'chunk-upload'=>[
				'class'=>'dungang\storage\ChunkUploadAction'
			],
			'delete'=>[
				'class'=>'dungang\storage\DeleteAction'
			],
		];
	}
}

class OssController extends Controller {
	private $driverConfig = [
		'class'=>'dungang\storage\driver\AliyunOSS',
		'accessKey'=>'xxxx',
		'accessSecret'=>'xxxxxx',
		'endpoint'=>'http://oss-cn-shenzhen.aliyuncs.com',
		'bucket'=>'bucketName',
		'imageBaseUrl'=>'http://bucketName.oss-cn-shenzhen.aliyuncs.com',
		'fileBaseUrl'=>'http://bucketName.oss-cn-shenzhen.aliyuncs.com',
		'dirSuffix'=> date('Y-m-d')
	];
	public function actions(){
		return [
			'init-upload'=>[
				'class'=>'dungang\storage\InitAction',
				'driverConfig'=>$this->driverConfig,
			],
			'chunk-upload'=>[
				'class'=>'dungang\storage\ChunkUploadAction',
				'driverConfig'=>$this->driverConfig
			],
			'delete'=>[
				'class'=>'dungang\storage\DeleteAction',
				'driverConfig'=>$this->driverConfig
			],
		];
	}
}

'init-upload'=>[
	'class'=>'dungang\storage\InitAction',
	'driverConfig'=>$this->driverConfig,
	'
],

'chunk-upload'=>[
	'class'=>'dungang\storage\ChunkUploadAction',
	'driverConfig'=>array_merge([
		'behaviors'=>[
			'saveImageInfo'=>'可以配置自己实现的行为,比如保存图片的信息,通过event->payload获取ChunkResponse对象实例'
		],
	],$this->driverConfig)
],
json
{
	"isOk":true,
	"error":"",
	"key":"uploader\\test\\905cd7faa06cee41e0deb1a0502a868c.jpg",
	"uploadId":"370af9d2-c565-4b8e-9fa4-186d150affab",
	"completed":false //表示还没完成此文件所有的分片上传
}


{
	"isOk":true,
	"error":"",
	"key":"uploader\\test\\905cd7faa06cee41e0deb1a0502a868c.jpg",
	"uploadId":"370af9d2-c565-4b8e-9fa4-186d150affab",
	"completed":true //表示已完成此文件所有的分片上传
}