PHP code example of juckzhang / yii2-upload
1. Go to this page and download the library: Download juckzhang/yii2-upload 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/ */
juckzhang / yii2-upload example snippets
return [
'advertisement' => [
'extensions' => null,
'mimeTypes' => null,
'minSize' => 1024,
'maxSize' => 10 * 1048576,
'uploadRequired' => '上传文件不存在!',
'tooBig' => '文件大小超过限制',
'tooSmall' => '上传文件太小',
'tooMany' => '上传文件数量超过限制',
'wrongExtension' => '文件扩展名不支持',
'wrongMimeType' => '文件mime-type不支持',
'path' => realpath(__DIR__ . '/../upload'),
'urlPrefix' => 'http://localhost',
'remoteUpload' => true,
'recursive' => false,
],
];
/** QiNiu **/
return [
'components' => [
'uploadTool' => [
'class' => 'juckzhang\drivers\UploadTool',
'handler' => [
'class' => 'juckzhang\drivers\UploadQiNiu',
'diskName' => 'privateBucket',
'config' => [
'class' => 'dcb9\qiniu\Component',
'accessKey' => 'YOUR ACCESSKEY',
'secretKey' => 'YOUR SECRETKEY',
'disks' => [
'privateBucket' => [
'bucket' => 'YOUR BUCKET',
'baseUrl' => 'http://your-domain/',
'isPrivate' => true,
'zone' => 'zone1', // 可设置为 zone0, zone1 @see \Qiniu\Zone
],
],
],
],
],
]
/** OR AliYun **/
return [
'components' => [
'uploadTool' => [
'class' => 'juckzhang\drivers\UploadTool',
'handler' => [
'class' => 'juckzhang\drivers\UploadAliYun',
'accessKeyId' => 'YOUR ACCESSSKEYID',
'accessKeySecret' => 'ACCESSKEYSECRET',
'bucket' => 'test-zaizaitv-upload',
'endPoint' => 'http://your-domain/',
],
],
],
]
/** OR Ftp **/
return [
'components' => [
'uploadTool' => [
'class' => 'juckzhang\drivers\UploadTool',
'handler' => [
'class' => 'juckzhang\drivers\UploadFtp',
'config' => [
'class' => 'gftp\FtpComponent',
'connectionString' => 'ftp://USERNAME:PASSWORD@HOST:PORT',
'driverOptions' => [
'timeout' => 30,
],
],
],
],
],
]
\Yii::$app->get('uploadTool')->uploadFile($remoteFileName,$localFileName);
/**单文件上传**/
juckzhang\UploadService::getService()->upload($sceneType);
/**多文件上传**/
juckzhang\UploadService::getService()->multiUpload($sceneType);
'controllerMap' => [
'upload' => [
'class' => 'juckzhang\controllers\UploadController',
],
],