TP3.1 中不支持Composer 就无法用composer 安装
下载历史的SDK
https://github.com/qiniu/php-sdk/releases/tag/v7.0.8
下载下来放到 Think 目录下的Vendor下
进入代码
HTML的代码
<form id="upload" method='post' action="file" enctype="multipart/form-data"><input name="file" type="file" /><input type="submit" value="提交" > </form>
控制器
use Qiniu\Storage\UploadManager;
use Qiniu\Auth;
public function file(){require __DIR__.'/../../../../Think/Vendor/Qi/autoload.php'; //导入类自动加载器$accessKey="z8NmWKeLfzU8ev6V95xo*************"; //七牛的钥密$secretKey="SMqml0QjGtU2LHbBKhEB**************";//先上传到本地header("Content-type: text/html; charset=utf-8");import('ORG.Net.UploadFile');$upload = new UploadFile();// 实例化上传类$upload->maxSize = 113145728 ;// 设置附件上传大小$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg','exe','zip','doc');// 设置附件上传类型$upload->savePath = './../Public/';// 设置附件上传目录if(!$upload->upload()) {// 上传错误提示错误信息$this->error($upload->getErrorMsg());}else{// 上传成功 获取上传文件信息$info = $upload->getUploadFileInfo();$lastPath=$info[0]['savepath'] . $info[0]['savename'];dump($lastPath);dump($info);// 构建鉴权对象$auth = new Auth($accessKey, $secretKey);// 要上传的空间$bucket = 'wlphp';// 生成上传 Token$token = $auth->uploadToken($bucket);// 上传到七牛后保存的文件名$key = $info[0]['savename'];// 初始化 UploadManager 对象并进行文件的上传。$uploadMgr = new UploadManager();// 调用 UploadManager 的 putFile 方法进行文件的上传。list($ret, $err) = $uploadMgr->putFile($token, $key, $lastPath);if ($err !== null) {var_dump($err);} else {$URL="http://p7h441d6x.bkt.clouddn.com/";$URL=$URL . $ret['key'];var_dump($ret['key']);dump($URL);}} }
上传完成到自己的七牛看一看就OK!