<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之旅 廣告
                >[info] 請到 `extra/qiniu.php` 配置你的七牛 `accessKey` 等配置信息,然后使用 `extend/Qiniu.php` 類輕松使用七牛上傳文件 ##配置 `extra/qiniu.php` ``` return [ // 七牛云存儲配置信息 "accessKey" => "", "secretKey" => "", "bucket" => "", // 存儲空間 "domain" => "http://qiniu.tianpian.net.cn/", // 訪問域名 ]; ``` ##實例化配置 實例化一個單例對象時傳入的配置,`\Qiniu::instance($config = [])` ``` $config = [ 'mimes' => [], // 允許上傳的文件 mime 類型 'max_size' => 0, // 上傳的文件大小限制 (0-不做限制) 'exts' => [], // 允許上傳的文件后綴,不包含點,例如 ['jpg', 'png', 'gif'] 'url' => "http://upload.qiniu.com/", // 上傳的地址 'param' => [], // 參數 ]; ``` ##上傳單個文件,文件直傳 直接傳入文件路徑名上傳文件 ###方法 `\Qiniu::instance($config = [])->uploadOne($file_path,$prefix="",$name=null,$token=null,$params = null, $mime = 'application/octet-stream', $checkCrc = false)` ###參數 | 名稱 | 類型 | 說明 | | --- | --- | --- | | file_path | string | 要上傳文件路徑的全名 | | prefix | string | 隨機字符串前綴,前后端統一隨機字符串生成規則,請參考 [隨機字符串](隨機字符串) | | name | null \| string | 為空自動生成隨機字符串,如果指定時需加上文件擴展名 | | token | null \| string | 為空自動獲取 | | params | null \| array | 自定義變量,規則參考 [七牛 - 開發者指南](http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar) | | mime | string | 上傳文件的 mime | | checkCrc | bool | 是否校驗crc32 | ###使用示例 以下示例是百度編輯器 (Ueditor) 抓取遠程圖片到七牛云的方法 ``` /** * 遠程圖片抓取 */ public function remote() { $data = Request::instance()->param(); // 遍歷上傳 $ret["list"] = []; $upload = \Qiniu::instance(); $model = Loader::model("File"); foreach ($data['source'] as $source) { $file_name = basename($source); $file_path = TEMP_PATH . $file_name; // 遠程下載圖片到本地 $file_path = \File::downloadImage($source, $file_path, 1); // 上傳圖片 $info = $upload->uploadOne($file_path, "image/"); if ($error = $upload->getError()) { $ret['list'][] = ['state' => $error]; } else { // 上傳成功,將數據寫入到本地數據庫中 $model->insertRecord($info, 1); $ret['list'][] = [ 'state' => "SUCCESS", 'url' => $info['key'], 'source' => $source, ]; } // 刪除臨時下載的文件 unlink($file_path); } return Response::create($ret, 'json'); } ``` >[info] 上傳失敗返回 false ,通過 `\Qiniu::instance()->getError()` 獲取錯誤信息 ##多個文件上傳 使用 ajax 或 file 控件直接上傳文件,上傳后帶有 `$_FILES` 變量的上傳 ###方法 `\Qiniu::instance()->upload($prefix="",$params = null, $checkCrc = false)` ###參數 | 名稱 | 類型 | 說明 | | --- | --- | --- | | prefix | string | 隨機字符串前綴,前后端統一隨機字符串生成規則,請參考 [隨機字符串](隨機字符串) | | params | null \| array | 自定義變量,規則參考 [七牛 - 開發者指南](http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar) | | checkCrc | bool | 是否校驗crc32 | ###使用示例 以下示例是百度編輯器 (Ueditor) 上傳圖片和文件到七牛云的方法 ``` /** * 圖片上傳 */ public function upload($prefix = "image/", $cate = 1) { $upload = \Qiniu::instance(); $info = $upload->upload($prefix); $error = $upload->getError(); // 保存圖片到數據庫 if ($info) { $model = Loader::model("File"); foreach ($info as $v) { if (is_array($v)) { $model->insertRecord($v, $cate); } } } if (!empty($error)) { $ret['state'] = $error; } else { $ret = [ "state" => 'SUCCESS', "url" => $info[0]['key'], "title" => $info[0]['name'], "original" => $info[0]['name'], "type" => $info[0]['type'], "size" => $info[0]['size'], ]; } return Response::create($ret, 'json'); } ``` >[info] 如果是有多個 `input[type='file']` 的控件上傳,則返回的數據是: ``` $ret = [ 'key1' => [ ['key' => '上傳到七牛的文件名', 'hash' => '文件hash值', 'name' => '原文件名', 'type' => '文件mime', 'ext' => '文件擴展名'], ['key' => '上傳到七牛的文件名', 'hash' => '文件hash值', 'name' => '原文件名', 'type' => '文件mime', 'ext' => '文件擴展名'], ], 'key2' => [ ['key' => '上傳到七牛的文件名', 'hash' => '文件hash值', 'name' => '原文件名', 'type' => '文件mime', 'ext' => '文件擴展名'], '錯誤信息', ], ]; ``` >[info] 如果出現錯誤,返回的文件信息數組的地方變成了錯誤信息,判斷該位置是否是數組即可,可以通過 `\Qiniu::instance()->getError()` 獲取最后一個錯誤信息 如果只有一個 `input[type='file']` 的控件上傳,則返回的數據是: ~~~ $ret = [ ['key' => '上傳到七牛的文件名', 'hash' => '文件hash值', 'name' => '原文件名', 'type' => '文件mime', 'ext' => '文件擴展名'], '錯誤信息', ]; ~~~ >[info] 返回的文件名為生成的隨機字符串 ##獲取七牛上傳token 如果想直接獲取 `token` 調用此方法即可 ###方法 直接返回 `token` `\Qiniu::token($expires = 3600, $bucket = null ,$key = null, $policy = null, $strictPolicy = true)` ###參數 | 名稱 | 類型 | 說明 | | --- | --- | --- | | expires | int | token 過期時間,單位秒 | | bucket | string | 七牛對象存儲 bucket ,為空則取配置信息里的 bucket | | key | mixed | key | | policy | mixed | policy | | strictPolicy | bool | strictPolicy | ###使用示例 以下示例是七牛上傳類里面的方法 ``` /** * 上傳單個文件,文件直傳 * @param $file_path * @param string $prefix 文件名前綴,可以模擬目錄 * @param null $name * @param null $token * @param null $params * @param string $mime * @param bool $checkCrc * @return bool */ public function uploadOne($file_path, $prefix = "", $name = null, $token = null, $params = null, $mime = 'application/octet-stream', $checkCrc = false) { if (empty($name)) $name = get_random($prefix) . "." . pathinfo($file_path, PATHINFO_EXTENSION); if (empty($token)) $token = self::token(); if (empty($mime)) $mime = 'application/octet-stream'; $this->error = null; list($ret, $error) = self::manager()->putFile($token, $name, $file_path, $params, $mime, $checkCrc); if ($error !== null) { $this->error = $error->message(); return false; } else { return $ret; } } ``` ##完美支持百度編輯器 (Ueditor) 在頁面引入 `ueditor` 的 js 文件后,然后實例化 `ueditor` 時增加 `serverUrl` 配置即可 ``` // HTML 代碼 <script id="editor" type="text/plain" style="height:400px"></script> // JavaScript 代碼 <script>window.UEDITOR_HOME_URL = '__LIB__/ueditor/1.4.3/'</script> <script type="text/javascript" charset="utf-8" src="__LIB__/ueditor/1.4.3/ueditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="__LIB__/ueditor/1.4.3/ueditor.all.min.js"> </script> <script type="text/javascript" charset="utf-8" src="__LIB__/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script> <script> $(function () { var ue = UE.getEditor('editor',{ serverUrl:'{:\\think\\Url::build("Ueditor/index")}' }); }) </script> ``` >[info] 具體使用方法和在線體驗請參考 [在線體驗 - 示例 - 百度編輯器](http://tpadmin.demo.tianpian.net.cn) 默認管理員帳號:admin,默認管理員密碼:123456
                  <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>

                              哎呀哎呀视频在线观看