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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 封裝上傳方法 > 一、打開項目在config文件夾下創建upload.php配置文件用來管理文件上傳的后綴和大小 ```php <?php return [ //定義允許上傳文件后綴的數組 'suffix_arr' => [ //允許圖片上傳的后綴 'image' => 'jpg,jpeg,png,gif', //允許上傳文件的后綴 'file' => 'zip,gz,doc,txt,pdf,xls', //... ], //定義允許上傳文件大小的數組 'size_arr' => [ //允許圖片上傳的大小 'image' => 10, //允許文件上傳的大小 'file' => 50 ], ]; ``` > 二、修改config\filesystem.php配置文件配置上傳根目錄及上傳規則 ```php <?php return [ // 默認磁盤 'default' => 'local', // 磁盤列表 'disks' => [ 'local' => [ 'type' => 'local', 'root' => app()->getRuntimePath() . 'storage', ], 'public' => [ // 磁盤類型 'type' => 'local', // 磁盤路徑 'root' => app()->getRootPath() . 'public/storage', // 磁盤路徑對應的外部URL路徑 'url' => '/storage', // 可見性 'visibility' => 'public', ], // 更多的磁盤配置信息 'excel' => [ // 磁盤類型 'type' => 'local', // 磁盤路徑 'root' => app()->getRootPath() . 'public', // 磁盤路徑對應的外部URL路徑 'url' => '/excel', // 可見性 'visibility' => 'public', ], ], ]; ``` > 在app\controller目錄下創建Upload.php類并編寫upload()文件上傳方法,如果是這樣加個post請求判斷 > > 放在common方法里的話,可以直接調用 ```php /** * 上傳方法 * @param $file * @param string $name * @param string $type * @return bool|\think\response\Json * * User: mi * Date: 2020-09-14 */ public function upload($file, $name = 'file', $type = 'file') { //接收文件上傳類型 // $type = request()->param('type', '', 'trim'); // $name = request()->param('name', '', 'trim'); // // //獲取表單上傳文件 // $file = request()->file('file'); //組裝文件保存目錄 $upload_dir = '/' . $type . '/' . $name; try { //從config/upload.php配置文件中讀取允許上傳的文件后綴和大小 $suffix_config = config('upload.suffix_arr'); $size_config = config('upload.size_arr'); if (empty($size_config[$type]) || empty($size_config[$type])) { return false; } else { $suffix = $suffix_config[$type]; $size = $size_config[$type]; } //驗證器驗證上傳的文件 validate(['file' => [ //限制文件大小 'fileSize' => $size * 1024 * 1024, //限制文件后綴 'fileExt' => $suffix ]], [ 'file.fileSize' => '上傳的文件大小不能超過' . $size . 'M', 'file.fileExt' => '請上傳后綴為:' . $suffix . '的文件' ])->check(['file' => $file]); //上傳文件到本地服務器 $filename = \think\facade\Filesystem::disk('public')->putFile($upload_dir, $file); if ($filename) { $src = '/storage/' . $filename; // return json(['code' => 1, 'result' => $src]); return $src; } else { return json(['code' => 0, 'msg' => '上傳失敗']); } } catch (ValidateException $e) { return json(['code' => 0, 'msg' => $e->getMessage()]); } } ```
                  <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>

                              哎呀哎呀视频在线观看