正在显示
3 个修改的文件
包含
38 行增加
和
14 行删除
app/Http/Controllers/File/BaseController.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :BaseController.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2023/7/26 11:44 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Http\Controllers\File; | ||
| 11 | + | ||
| 12 | +use App\Http\Controllers\Controller; | ||
| 13 | +use http\Client; | ||
| 14 | +use Illuminate\Http\Request; | ||
| 15 | +use Illuminate\Support\Facades\Cache; | ||
| 16 | + | ||
| 17 | +class BaseController extends Controller | ||
| 18 | +{ | ||
| 19 | + public function __construct() | ||
| 20 | + { | ||
| 21 | + $http_origin = "*"; | ||
| 22 | + if(isset($_SERVER['HTTP_ORIGIN'])){ | ||
| 23 | + $http_origin = $_SERVER['HTTP_ORIGIN']; | ||
| 24 | + } | ||
| 25 | + header("Access-Control-Allow-Origin:".$http_origin); | ||
| 26 | + header('Access-Control-Allow-Methods:POST,GET'); //支持的http 动作 | ||
| 27 | + header('Access-Control-Allow-Credentials: true'); | ||
| 28 | + header('Access-Control-Max-Age: 1000'); | ||
| 29 | + header('Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept, Authorization, token'); //响应头 请按照自己需求添加。 | ||
| 30 | + if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') { | ||
| 31 | + exit; | ||
| 32 | + } | ||
| 33 | + } | ||
| 34 | +} |
| @@ -10,7 +10,7 @@ use Illuminate\Http\Exceptions\HttpResponseException; | @@ -10,7 +10,7 @@ use Illuminate\Http\Exceptions\HttpResponseException; | ||
| 10 | use Illuminate\Http\JsonResponse; | 10 | use Illuminate\Http\JsonResponse; |
| 11 | use Illuminate\Support\Facades\Cache; | 11 | use Illuminate\Support\Facades\Cache; |
| 12 | 12 | ||
| 13 | -class FileController | 13 | +class FileController extends BaseController |
| 14 | { | 14 | { |
| 15 | public $upload_img = [ | 15 | public $upload_img = [ |
| 16 | //设置静态缓存参数(304) | 16 | //设置静态缓存参数(304) |
| @@ -43,18 +43,7 @@ class FileController | @@ -43,18 +43,7 @@ class FileController | ||
| 43 | ]; | 43 | ]; |
| 44 | public function __construct() | 44 | public function __construct() |
| 45 | { | 45 | { |
| 46 | - $http_origin = "*"; | ||
| 47 | - if(isset($_SERVER['HTTP_ORIGIN'])){ | ||
| 48 | - $http_origin = $_SERVER['HTTP_ORIGIN']; | ||
| 49 | - } | ||
| 50 | - header("Access-Control-Allow-Origin:".$http_origin); | ||
| 51 | - header('Access-Control-Allow-Methods:POST,GET'); //支持的http 动作 | ||
| 52 | - header('Access-Control-Allow-Credentials: true'); | ||
| 53 | - header('Access-Control-Max-Age: 1000'); | ||
| 54 | - header('Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept, Authorization, token'); //响应头 请按照自己需求添加。 | ||
| 55 | - if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') { | ||
| 56 | - exit; | ||
| 57 | - } | 46 | + parent::__construct(); |
| 58 | $this->request = request(); | 47 | $this->request = request(); |
| 59 | $this->param = $this->request->all(); | 48 | $this->param = $this->request->all(); |
| 60 | $this->config = config('filesystems.disks.upload'); | 49 | $this->config = config('filesystems.disks.upload'); |
| @@ -14,7 +14,7 @@ use Illuminate\Http\JsonResponse; | @@ -14,7 +14,7 @@ use Illuminate\Http\JsonResponse; | ||
| 14 | use Illuminate\Support\Facades\Cache; | 14 | use Illuminate\Support\Facades\Cache; |
| 15 | use Intervention\Image\Facades\Image; | 15 | use Intervention\Image\Facades\Image; |
| 16 | 16 | ||
| 17 | -class ImageController extends Controller | 17 | +class ImageController extends BaseController |
| 18 | { | 18 | { |
| 19 | public $upload_img = [ | 19 | public $upload_img = [ |
| 20 | //设置静态缓存参数(304) | 20 | //设置静态缓存参数(304) |
| @@ -52,6 +52,7 @@ class ImageController extends Controller | @@ -52,6 +52,7 @@ class ImageController extends Controller | ||
| 52 | 52 | ||
| 53 | public function __construct() | 53 | public function __construct() |
| 54 | { | 54 | { |
| 55 | + parent::__construct(); | ||
| 55 | $this->request = request(); | 56 | $this->request = request(); |
| 56 | $this->token = $this->request->header('token'); | 57 | $this->token = $this->request->header('token'); |
| 57 | $this->cache = Cache::get($this->token); | 58 | $this->cache = Cache::get($this->token); |
-
请 注册 或 登录 后发表评论