• thinkphp5 图片上传七牛云


    <?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

  • 相关阅读:
    AGC037F Counting of Subarrays
    AGC025F Addition and Andition
    CF506C Mr. Kitayuta vs. Bamboos
    AGC032D Rotation Sort
    ARC101F Robots and Exits
    AGC032E Modulo Pairing
    CF559E Gerald and Path
    CF685C Optimal Point
    聊聊Mysql索引和redis跳表
    什么是线程安全
  • 原文地址:https://www.cnblogs.com/yehuisir/p/11268873.html
Copyright © 2020-2023  润新知