作者 lyh

gx

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