正在显示
1 个修改的文件
包含
14 行增加
和
0 行删除
| @@ -257,6 +257,7 @@ class ImageController extends Controller | @@ -257,6 +257,7 @@ class ImageController extends Controller | ||
| 257 | * @time :2023/7/19 17:59 | 257 | * @time :2023/7/19 17:59 |
| 258 | */ | 258 | */ |
| 259 | public function download(){ | 259 | public function download(){ |
| 260 | + $this->setHeader(); | ||
| 260 | $imageModel = new ImageModel(); | 261 | $imageModel = new ImageModel(); |
| 261 | $info = $imageModel->read(['hash' => $this->param['hash']]); | 262 | $info = $imageModel->read(['hash' => $this->param['hash']]); |
| 262 | if ($info === false) { | 263 | if ($info === false) { |
| @@ -280,6 +281,19 @@ class ImageController extends Controller | @@ -280,6 +281,19 @@ class ImageController extends Controller | ||
| 280 | readfile($fileUrl); | 281 | readfile($fileUrl); |
| 281 | } | 282 | } |
| 282 | 283 | ||
| 284 | + public function setHeader(){ | ||
| 285 | + // 设置跨域请求头部 | ||
| 286 | + header('Access-Control-Allow-Origin: *'); | ||
| 287 | + header('Access-Control-Allow-Methods: GET'); | ||
| 288 | + header('Access-Control-Allow-Headers: Content-Type'); | ||
| 289 | + // 处理预检请求 | ||
| 290 | + if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { | ||
| 291 | + header('Access-Control-Allow-Origin: *'); | ||
| 292 | + header('Access-Control-Allow-Methods: GET'); | ||
| 293 | + header('Access-Control-Allow-Headers: Content-Type'); | ||
| 294 | + exit; | ||
| 295 | + } | ||
| 296 | + } | ||
| 283 | /** | 297 | /** |
| 284 | * @param $msg | 298 | * @param $msg |
| 285 | * @param string $code | 299 | * @param string $code |
-
请 注册 或 登录 后发表评论