<?php

namespace app\cxc\controller;

use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
use think\Controller;
use think\Db;
use think\Request; 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);
}
} }

thinkphp5 图片上传七牛云-LMLPHP

thinkphp5 图片上传七牛云-LMLPHP

thinkphp5 图片上传七牛云-LMLPHP

-----------------------------------------------------------图片后缀没有jpg|png--------------------------------------------------------

thinkphp5 图片上传七牛云-LMLPHP

thinkphp5 图片上传七牛云-LMLPHP

thinkphp5 图片上传七牛云-LMLPHP

thinkphp5 图片上传七牛云-LMLPHP

thinkphp5 图片上传七牛云-LMLPHP

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

thinkphp5 图片上传七牛云-LMLPHP

thinkphp5 图片上传七牛云-LMLPHP

thinkphp5 图片上传七牛云-LMLPHP

thinkphp5 图片上传七牛云-LMLPHP

注意引入七牛包
先使用 composer 引入七牛:

composer require qiniu/php-sdk

05-11 23:02