<?php
namespace Home\Controller;
use Think\Controller;
class BaseController extends Controller{
//本地配置参数
protected $local_config = [
‘maxSize’ => 5242880,
‘rootPath’ => ‘./Uploads/‘,
‘saveName’ => array(‘uniqid’,’’),
‘autoSub’ => true,
‘subName’ => array(‘date’,’Ymd’),
];
//七牛配置参数
protected $qiniu_config = [
‘secretKey’ => ‘****‘, //七牛SK YKtjhUMus07YUkT0bTudC2D1Tnm62JaWJ3JJkrIC
‘accessKey’ => ‘****‘, //七牛AK 8f4JUUDc1GFeEOaGerbwpt1aM7XN1GFbiuLKY35T
‘domain’ => ‘****‘, //七牛空间地址URL
‘bucket’ => ‘****‘, //七牛空间名称
];
protected function uploadOne($file){
$upload = new \\Think\\Upload($this->local\_config,'Qiniu',$this->qiniu\_config);
$info = $upload->uploadOne($file);
if (!$info) {
return \[201, $upload->getError()\];
}
return \[200, $info\];
}
protected function uploads($files){
$upload = new \\Think\\Upload($this->config);
$info = $upload->upload($files);
if (!$info) {
return \[201, $upload->getError()\];
}
foreach ($info as $v) {
$pArray\[\] = "http://".$this->config\['driverConfig'\]\['domain'\]."/".strtr($v\['name'\], '/', '_');
}
return \[200, $pArray\];
}
}