<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                >[danger] 七牛云圖片上傳封裝類 ``` composer require qiniu/php-sdk ``` ```php <?php // 本文件放入TP6.0的extend目錄下 extend/Qiniu.php use Qiniu\Auth; use Qiniu\Storage\UploadManager; // 設置配置參數 // Qiniu::setConfig([ // 'bucket' => 'xxxxx', // 'domain' => 'https://test.itqaq.com', // 'accessKey' => 'l_OnndRIVj17ZwIKMOZBLorh5dK4xxxxxxx', // 'secretKey' => '7fXF7wbOWcC5pUJKmGz3N8xxxxxxxxxxxxx', // ]); // 執行上傳 // Qiniu::upload('img', 'art/thumb'); // 上傳成功 $arr // 'result' =>true // 'msg' => 上傳成功 // 'path' => 帶域名的圖片URL // // 上傳失敗 $arr // 'result' => false // 'msg' => 錯誤信息 /** * 七牛云封裝類 * composer require qiniu/php-sdk * * @author liang <23426945@qq.com> * @version 1.0.0 * @datetime 2020-07-20 * @homepage www.itqaq.com */ class Qiniu { private static $bucket; private static $domain; private static $accessKey; private static $secretKey; /** * 私有化構造方法 * 禁止類在外部被實例化 */ private function __construct(){} /** * 設置七牛云配置參數 */ public static function setConfig($config) { // 存儲空間名稱 self::$bucket = $config['bucket']; // 存儲空間對應的域名 self::$domain = $config['domain']; // 用于簽名的公鑰 AK self::$accessKey = $config['accessKey']; // 用于簽名的私鑰 SK self::$secretKey = $config['secretKey']; } /** * 文件上傳到七牛云 */ public static function upload($field, $dirname = '') { // 捕獲異常 try { // 此時可能會報錯 // 比如:上傳的文件過大,超出了配置文件中限制的大小 $file = request()->file($field); // 如果表單沒有設置文件上傳需要的編碼 $file始終是null if (is_null($file)) throw new \think\Exception('沒有文件上傳,請檢查當前是否為post請求并且是否設置了編碼: enctype="multipart/form-data"'); } catch (\think\Exception $e) { // 獲取異常錯誤信息 $errMsg = $e->getMessage(); // 上傳失敗,返回錯誤信息 return self::_rtnData(false, self::_chinese($errMsg)); } // 臨時文件路徑 $tmpName = $file->getRealPath(); // 原始文件后綴名 $ext = $file->getOriginalExtension(); // 初始化鑒權對象 $auth = new Auth(self::$accessKey, self::$secretKey); // 生成上傳Token $token = $auth->uploadToken(self::$bucket); // 上傳管理類 構建UplaodManager對象 $uploadMgr = new UploadManager(); // 目錄名 if ($dirname != '') $dirname .= '/'; // 隨機文件名 $path = $dirname . md5(microtime(true) . mt_rand(1, 1e9)) . '.' . $ext; // 執行文件上傳到七牛云 $info = $uploadMgr->putFile($token, $path, $tmpName); // 上傳到七牛云后的路徑 $qiniuPath = self::$domain . '/' . $info[0]['key']; // 返回上傳成功的狀態信息 return self::_rtnData(true, '上傳成功', $qiniuPath); } /** * 文件上傳返回結果數組 */ private static function _rtnData(bool $result, $msg = null, $path = null) { // 過濾掉值為null的數組元素 return array_filter(compact('result', 'msg', 'path'), function($v){ return !is_null($v); }); } /** * 英文轉為中文 */ private static function _chinese($msg) { $data = [ // 上傳錯誤信息 'unknown upload error' => '未知上傳錯誤!', 'file write error' => '文件寫入失敗!', 'upload temp dir not found' => '找不到臨時文件夾!', 'no file to uploaded' => '沒有文件被上傳!', 'only the portion of file is uploaded' => '文件只有部分被上傳!', 'upload File size exceeds the maximum value' => '上傳文件大小超過了最大值!', 'upload write error' => '文件上傳保存錯誤!', ]; return $data[$msg] ?? $msg; } /** * 私有化克隆方法 * 禁止類的實例在外部被克隆 */ private function __clone(){} } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看