<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### 需要composer引入圖像處理擴展 `composer require topthink/think-image` 引入類 `use think\Config as FaConfig;` ``` /** * 上傳文件 * @ApiMethod (POST) * @param File $file 文件流 */ public function upload() { $file = $this->request->file('file'); if (empty($file)) { $this->error(__('No file upload or server upload limit exceeded')); } //判斷是否已經存在附件 $sha1 = $file->hash(); $upload = FaConfig::get('upload'); preg_match('/(\d+)(\w+)/', $upload['maxsize'], $matches); $type = strtolower($matches[2]); $typeDict = ['b' => 0, 'k' => 1, 'kb' => 1, 'm' => 2, 'mb' => 2, 'gb' => 3, 'g' => 3]; $size = (int)$upload['maxsize'] * pow(1024, isset($typeDict[$type]) ? $typeDict[$type] : 0); $fileInfo = $file->getInfo(); $suffix = strtolower(pathinfo($fileInfo['name'], PATHINFO_EXTENSION)); $suffix = $suffix && preg_match("/^[a-zA-Z0-9]+$/", $suffix) ? $suffix : 'png'; //驗證是否為圖片文件 $imagewidth = $imageheight = 0; if (in_array($fileInfo['type'], ['image/gif', 'image/jpg', 'image/jpeg', 'image/bmp', 'image/png', 'image/webp']) || in_array($suffix, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'webp'])) { $imgInfo = getimagesize($fileInfo['tmp_name']); if (!$imgInfo || !isset($imgInfo[0]) || !isset($imgInfo[1])) { $this->error(__('Uploaded file is not a valid image')); } $imagewidth = isset($imgInfo[0]) ? $imgInfo[0] : $imagewidth; $imageheight = isset($imgInfo[1]) ? $imgInfo[1] : $imageheight; } $replaceArr = [ '{year}' => date("Y"), '{mon}' => date("m"), '{day}' => date("d"), '{hour}' => date("H"), '{min}' => date("i"), '{sec}' => date("s"), '{random}' => Random::alnum(16), '{random32}' => Random::alnum(32), '{filename}' => $suffix ? substr($fileInfo['name'], 0, strripos($fileInfo['name'], '.')) : $fileInfo['name'], '{suffix}' => $suffix, '{.suffix}' => $suffix ? '.' . $suffix : '', '{filemd5}' => md5_file($fileInfo['tmp_name']), ]; $savekey = $upload['savekey']; $savekey = str_replace(array_keys($replaceArr), array_values($replaceArr), $savekey); $uploadDir = substr($savekey, 0, strripos($savekey, '/') + 1); $fileName = substr($savekey, strripos($savekey, '/') + 1); $splInfo = $file->move(ROOT_PATH . '/public' . $uploadDir, $fileName); if ($splInfo) { /*縮略圖*/ $vs = $splInfo->getSaveName(); $img = \think\Image::open($splInfo); /*解決圖片旋轉90問題_START*/ $str = $splInfo->getfilename(); $exif = exif_read_data($str); if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 8: /*通用的是8*/ $img->rotate(90)->thumb(150, 150)->save(ROOT_PATH . '/public' . $uploadDir . $vs); break; case 3: /*IOS選擇文件是3*/ $img->rotate(180)->thumb(150, 150)->save(ROOT_PATH . '/public' . $uploadDir . $vs); break; case 6: /*IOS相機是6*/ $img->rotate(90)->thumb(150, 150)->save(ROOT_PATH . '/public' . $uploadDir . $vs); break; } } else { $img->thumb(150, 150)->save(ROOT_PATH . '/public' . $uploadDir . $vs); } /*解決圖片旋轉90問題_END*/ $params = array( 'admin_id' => 0, 'user_id' => (int)$this->auth->id, 'filesize' => $fileInfo['size'], 'imagewidth' => $imagewidth, 'imageheight' => $imageheight, 'imagetype' => $suffix, 'imageframes' => 0, 'mimetype' => $fileInfo['type'], 'url' => $uploadDir . $splInfo->getSaveName(), 'uploadtime' => time(), 'storage' => 'local', 'sha1' => $sha1, ); $attachment = new \app\common\model\Attachment; $attachment->data(array_filter($params)); $attachment->save(); \think\Hook::listen("upload_after", $attachment); $this->success(__('Upload successful'), [ 'full_url' => request()->domain() . $uploadDir . $splInfo->getSaveName(), 'url' => $uploadDir . $splInfo->getSaveName() ]); } else { // 上傳失敗獲取錯誤信息 $this->error($file->getError()); } } 補充(重中之重): $str = $splInfo->getfilename(); getfilename()方法是修改了底層旨在獲取文件服務器地址:方法 文件路徑:thinkphp\library\think\File.php public function getfilename($name = '') { return isset($this->filename[$name]) ? $this->filename[$name] : $this->filename; } $exif = exif_read_data($str); 這個方法需要php安裝 exif擴展 ``` 返回示例: ![在這里插入圖片描述](https://img-blog.csdnimg.cn/20201219113527412.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0MDUwMzYw,size_16,color_FFFFFF,t_70)
                  <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>

                              哎呀哎呀视频在线观看