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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                >[danger] TP 內置的文件上傳(文件上傳到服務器) #### 1. 使用方法 --- **簡單示例** ```php // 返回數組 Upload::putFile('磁盤', '文件字段域', '目錄名'); ``` ```php Upload::putFile('public', 'img'); Upload::putFile('public', 'img', 'thumb'); ``` **`上傳成功`和 `上傳失敗` 時的返回值** ![](https://img.itqaq.com/art/content/a86cef6ea50b6700cb9a72f4a81096c3.png) ![](https://img.itqaq.com/art/content/fdc07240008ef14ab5c3b4bd544331aa.png) #### 2. 文件上傳封裝類 --- ```php <?php // 本文件放在TP6.0.*的extend目錄下 // extend/Upload.php use think\facade\Config; use think\facade\Filesystem; use think\exception\ValidateException; /** * 文件上傳封裝 * @author liang * @datetime 2020-07-01 */ class Upload { /** * 執行文件上傳 * @param string $disks 磁盤名稱 * @param string $field 字段名 * @param string $dir 文件存放目錄名,默認和字段名相同 * @return array 文件上傳結果數組 */ public static function putFile(string $disks = '', string $field = '', string $dir = '') { // 此時也可能報錯 // 比如上傳的文件過大,超出了配置文件中限制的大小 try { $file = request()->file($field); } catch (\think\Exception $e) { return self::_rtnData(false, self::_languageChange($e->getMessage())); } // 確定使用的磁盤 $disks = $disks ?: Filesystem::getDefaultDriver(); // 文件存放目錄名稱 $dirname = $dir ?: $field; // 從存放目錄開始的存放路徑 $savename = Filesystem::disk($disks)->putFile($dirname, $file); // 完整路徑 $path = Filesystem::getDiskConfig($disks, 'url') . '/' . str_replace('\\', '/', $savename); // 返回上傳成功時的數組 return self::_rtnData(true, '上傳成功', $path); } /** * 英文轉為中文 */ private static function _languageChange($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 static function _rtnData(bool $result, $msg = null, $path = null) { // 過濾掉值為null的數組元素 return array_filter(compact('result', 'msg', 'path'), function($v){ return !is_null($v); }); } } ```
                  <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>

                              哎呀哎呀视频在线观看