Blogger Information
Blog 14
fans 0
comment 0
visits 15032
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
上传文件到七牛
krasenChen的博客
Original
775 people have browsed it

1//使用七牛官方最新的SDK   composer安装PHP SDK

composer require qiniu/php-sdk

2//上传文件到七牛

use Qiniu\Auth;

use Qiniu\Storage\UploadManger;


$cfg = [

    'access' => 'YOUR_ACCESS_KEY';

     'secret' => 'YOUR_SECRET_KEY';

    'bucket' => 'YOUR_BUCKET', 

    'domain' => 'https://images.your_domain.com';

];

     $auth = new Auth($cfg['access'],  $cfg['secret']);

     //创建一个过期时间为1小时的临时上传令牌

     $token = $auth->uploadToken($cfg['bucket'], null, 3600);

     $filePath =  "./illustrationo.png";

     $uploadMgr = new UploadManager();

     list($ret, $err) = $uploadMgr->putFile($token, null, $filePath);

     if($err !== null) {

         $this->err = $err;

}else {

     echo $cfg['domain'] . '/' . $ret['key'];

}




Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post