1.先在verdor里新建一个文件夹: Qiniu
2.将SDK压缩包中的文件全部解压到Qiniu文件夹中
3.在Controller中,引用类
vendor('Qiniu.autoload');
use Qiniu\Auth as Auth;
use Qiniu\Storage\BucketManager;
use Qiniu\Storage\UploadManager;
4.在config.php中添加配置
'ACCESSKEY' => '',
'SECRETKEY' => '',
'BUCKET' => '',
'DOMAIN'=>'',
5.上传操作的函数
$file = request()->file('image');
$filePath = $file->getRealPath();
$ext = pathinfo($file->getInfo('name'), PATHINFO_EXTENSION);
$controllerName = 'index';
$key =substr(md5($file->getRealPath()) , 0, 5). date('YmdHis') . rand(0, 9999) . '.' . $ext;
$accessKey = config('ACCESSKEY');
$secretKey = config('SECRETKEY');
$auth = new Auth($accessKey, $secretKey);
$bucket = config('BUCKET');
$domain = config('DOMAINImage');
$token = $auth->uploadToken($bucket);
$uploadMgr = new UploadManager();
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
if ($err !== null) {
echo ["err"=>1,"msg"=>$err,"data"=>""];
} else {
var_dump($ret);
}