七牛云
public function upload(Request $request) { if(!$request->hasFile('image')) { exit('上传文件为空!'); } $file = $request->file('image'); $filename = $file->getClientOriginalName(); //判断文件上传过程中是否出错 if(!$file->isValid()) { exit('文件上传出错!'); } $basebath = realpath(public_path('uploads')); if (!file_exists($basebath)) { mkdir($basebath,0777,true); } $file->move($basebath,$filename); // 用于签名的公钥和私钥 $accessKey = 'yanWHFFlLhtsrNjOQNCtYqmRO3mdSLsXk_ovyyyb'; $secretKey = 'Oy3e9PKLRFlwAUSQ-5cSh7P0mIEBT-lLfNqoIsyG'; $bucket = "hanmengya"; // 构建鉴权对象 $auth = new Auth($accessKey, $secretKey); // 生成上传 Token $token = $auth->uploadToken($bucket); // 要上传文件的本地路径 $filePath = $basebath; //var_dump($filePath);die; // 上传到七牛后保存的文件名 $key = 'logo.png'; // 初始化 UploadManager 对象并进行文件的上传。 $uploadMgr = new UploadManager(); // 调用 UploadManager 的 putFile 方法进行文件的上传。 list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath."/5.jpg"); echo "\n====> putFile result: \n"; if ($err !== null) { var_dump($err); } else { var_dump($ret); } }