thinkphp七牛云对象存储的使用
切换到thinkphp安装目录,执行composer require qiniu/php-sdk命令:
D:\phpStudy1\WWW\yz>composer require qiniu/php-sdk Using version ^7.2 for qiniu/php-sdk ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Installing qiniu/php-sdk (v7.2.7): Downloading (100%) Writing lock file Generating autoload files |
php代码
public function index() { $accessKey = 'ythKLt0PwWAqEiRYSmmeB5sss'; $secretKey = 'hcGIkMySsxObuQpk9Gwsss'; // 初始化签权对象 $auth = new Auth($accessKey, $secretKey); $bucket = 'run'; $upToken = $auth->uploadToken($bucket); $this->assign('upToken',$upToken); return $this->fetch(); } |
html代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <form method="post" action="http://up.qiniup.com" enctype="multipart/form-data"> <input name="token" type="hidden" value="{$upToken}"> <input name="file" type="file" /> <input type="submit" value="上传"/> </form> </body> </html> |
上传一个文件,返回内容
{"hash":"Fv-CFqZYQ9qRTjc_imX8EpMYhjl8","key":"Fv-CFqZYQ9qRTjc_imX8EpMYhjl8"} |
浏览器访问
http://ptfxgijkl.bkt.clouddn.com/Fv-CFqZYQ9qRTjc_imX8EpMYhjl8