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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [toc] # 騰訊cos插件后臺操作工具類 > 此工具類的特色是同步的fastadmin騰訊cos插件的配置, 并且沿用的是插件自帶的sdk,不需要composer再去下載一個sdk,物盡其用 代碼片:https://gist.github.com/edk24/329b63df72774ad8b97f0664df0ff1a9 ## 代碼 位置:admin/library/QcloudCosUtil.php ```php <?php namespace app\admin\library; use app\common\model\Attachment; use think\Loader; /** * fastadmin 騰訊云cos后臺上傳工具類 (依賴cos插件) * * @author 余小波 <1421926943@qq.com> * @desc SDK:https://packagist.org/packages/qcloud/cos-sdk-v5 */ class QcloudCosUtil { /** * cos上傳配置 * * @var array */ protected $config = array(); /** * 插件目錄,默認空 * * @var string */ protected $addons_path = ''; /** * cos客戶端 * * @var \Qcloud\Cos\Client|null */ protected $cos_client = null; public function __construct() { if (!class_exists('\Qcloud\Cos\Client')) { Loader::addNamespace('Qcloud\Cos', $this->addons_path . str_replace('/', DS, 'library/Qcloud/Cos/')); } if (!class_exists('\GuzzleHttp\Command\Command')) { Loader::addNamespace('GuzzleHttp\Command', $this->addons_path . str_replace('/', DS, 'library/Guzzle/command/src/')); } if (!class_exists('\GuzzleHttp\Command\Guzzle\Description')) { Loader::addNamespace('GuzzleHttp\Command\Guzzle', $this->addons_path . str_replace('/', DS, 'library/Guzzle/guzzle-services/src/')); } $this->config = get_addon_config('cos'); $this->cos_client = new \Qcloud\Cos\Client(array( 'region' => $this->config['region'], 'credentials' => array( 'secretId' => $this->config['secretId'], 'secretKey' => $this->config['secretKey'], ) )); } /** * 上傳文件 (最大5GB) * * @param string $key * @param string|resource $body 二進制 或者 fopen(<file>, 'rb') * @return GuzzleHttp\Command\Result|null * @throws \Exception */ public function putObject($key, $body) { $result = $this->cos_client->putObject(array( 'Bucket' => $this->config['bucket'], 'Key' => $key, 'Body' => $body)); return $result; } /** * 上傳文件 [使用分塊上傳] (最大50T) * * @param string $key * @param string|resource $body 二進制 或者 fopen(<file>, 'rb') * @return \GuzzleHttp\Command\Result|null * @throws \Exception */ public function upload($key, $body) { $result = $this->cos_client->Upload($this->config['bucket'], $key, $body); return $result; } /** * fast文件上傳 (遵循fast保存路徑規則 最大文件限制50T) * * @param string $filename * @return \GuzzleHttp\Command\Result|null */ public function fastUpload($filename) { if (file_exists($filename) == false) { throw new \think\Exception('操作失敗,文件不存在'); } $md5 = md5_file($filename); $size = filesize($filename); $name = pathinfo($filename, PATHINFO_FILENAME); $suffix = pathinfo($filename, PATHINFO_EXTENSION); $type = mime_content_type($filename); $imagewidth = 0; $imageheight = 0; if (substr($type, 0, 5) == 'image') { $imageinfo = getimagesize($filename); if ($imageinfo) { $imagewidth = $imageinfo[0]; $imageheight = $imageinfo[1]; } } // /uploads/{year}{mon}{day}/{filemd5}{.suffix} $url = str_replace('{year}', date('Y'), $this->config['savekey']); $url = str_replace('{mon}', date('m'), $url); $url = str_replace('{day}', date('d'), $url); $url = str_replace('{filemd5}', $md5, $url); $url = str_replace('{.suffix}', '.' . $suffix, $url); $result = $this->upload($url, fopen($filename, 'rb')); if ($result == null) { return false; } // 保存到附件中 $attachment = Attachment::where('url', $url)->where('storage', 'cos')->find(); if (!$attachment) { $params = array( 'admin_id' => (int)session('admin.id'), 'user_id' => (int)cookie('uid'), 'filesize' => $size, 'filename' => $name . '.' . $suffix, 'imagewidth' => $imagewidth, 'imageheight' => $imageheight, 'imagetype' => $suffix, 'imageframes' => 0, 'mimetype' => $type, 'url' => $url, 'uploadtime' => time(), 'storage' => 'cos', 'sha1' => $md5, ); Attachment::create($params); } return $result; } } ``` ## 使用方法 ```php $cos = new QcloudCosUtil(); $res = $cos->fastUpload('/home/yuxiaobo/Desktop/bd.zip'); var_dump($res); ```
                  <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>

                              哎呀哎呀视频在线观看