<?php namespace appcxccontroller; use QiniuAuth; use QiniuStorageUploadManager; use thinkController; use thinkDb; use thinkRequest; class Image extends Controller { public function index() { $accessKey = "HAfr-OZKBC2owaoQKAGrst-VWByJ8OnDxWxkxxxx"; $secretKey = "yAuRjhWrrAUTv-a8QmfBxc2BT3NHTtvke0vxxxx"; $bucketName = "wx_images"; $upManager = new UploadManager(); $auth = new Auth($accessKey, $secretKey); // $checkShop = new CheckShop(); $img_url = "https://image.qiniu.xxxxx.cn/c88xxxxeec21f0743585af302503700_portrait"; // $img = $checkShop->imgtobase64($img_url); //dump($img); //// 上传到七牛后保存的文件名 /// $key =substr(md5($file->getRealPath()) , 0, 5). date('YmdHis') . rand(0, 9999) . '.' . $ext; $ext = 'jpeg'; $key = substr(md5($img_url) , 0, 5). date('YmdHis') . rand(0, 9999) . '.' . $ext; $domain = "http://pvecso7n8.bkt.clouddn.com"; $token = $auth->uploadToken($bucketName); // dump($img); list($ret, $error) = $upManager->put($token, $key, file_get_contents($img_url)); dump($ret); if ($error !== null) { return ["err" => 1, "msg" => $error, "data" => ""]; } else { //返回图片的完整URL $imgPath = $domain . '/' . $key; //赋值 dump($imgPath); } } }
-----------------------------------------------------------图片后缀没有jpg|png--------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
注意引入七牛包
先使用 composer 引入七牛:
composer require qiniu/php-sdk