作者 lyh

gx

@@ -4,9 +4,7 @@ namespace App\Http\Controllers\file; @@ -4,9 +4,7 @@ namespace App\Http\Controllers\file;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Http\Controllers\type; 6 use App\Http\Controllers\type;
7 -use App\Http\Controllers\统一返回参数;  
8 use App\Models\File\Image as ImageModel; 7 use App\Models\File\Image as ImageModel;
9 -use App\Models\User\User as UserModel;  
10 use Illuminate\Http\Exceptions\HttpResponseException; 8 use Illuminate\Http\Exceptions\HttpResponseException;
11 use Illuminate\Http\JsonResponse; 9 use Illuminate\Http\JsonResponse;
12 use Illuminate\Support\Facades\Storage; 10 use Illuminate\Support\Facades\Storage;
@@ -43,7 +41,7 @@ class ImageController @@ -43,7 +41,7 @@ class ImageController
43 $this->path = $this->config['root'].$this->uploads['path'].'/'; 41 $this->path = $this->config['root'].$this->uploads['path'].'/';
44 } 42 }
45 43
46 - public function index($hash = '',$type = self::TYPE, $w = 0 ,$h = 0 ){ 44 + public function index($hash = '', $w = 0 ,$h = 0 ){
47 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) { 45 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
48 header("HTTP/1.1 304 Not Modified"); 46 header("HTTP/1.1 304 Not Modified");
49 exit; 47 exit;
@@ -54,12 +52,11 @@ class ImageController @@ -54,12 +52,11 @@ class ImageController
54 $this->response('指定图片不存在!', Code::USER_ERROR); 52 $this->response('指定图片不存在!', Code::USER_ERROR);
55 } 53 }
56 //查看缩略图是否存在 54 //查看缩略图是否存在
57 - $header['Content-Type'] = 'image/'.$info['type'];  
58 $filename = $this->path . $info['hash'] . $w . '_' . $h; 55 $filename = $this->path . $info['hash'] . $w . '_' . $h;
59 if(is_file($filename)){ 56 if(is_file($filename)){
60 $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT"; 57 $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
61 $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], 58 $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
62 - [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']); 59 + [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 1, $last_modified_time], $this->upload_img['header']);
63 $content = file_get_contents($filename); 60 $content = file_get_contents($filename);
64 $header['Content-Length'] = $info['size']; 61 $header['Content-Length'] = $info['size'];
65 }else{ 62 }else{
@@ -70,24 +67,20 @@ class ImageController @@ -70,24 +67,20 @@ class ImageController
70 $content = ''; 67 $content = '';
71 $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT"; 68 $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
72 $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], 69 $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
73 - [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']); 70 + [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 1, $last_modified_time], $this->upload_img['header']);
74 if ($w > 0 && $h > 0) { 71 if ($w > 0 && $h > 0) {
75 $path = $this->cacheImage($info, $w, $h); 72 $path = $this->cacheImage($info, $w, $h);
76 $content = file_get_contents($path); 73 $content = file_get_contents($path);
77 $header['Content-Length'] = strlen($content); 74 $header['Content-Length'] = strlen($content);
78 } else { 75 } else {
79 $content = file_get_contents($path); 76 $content = file_get_contents($path);
80 - $header['Content-Length'] = $info['size']; 77 + $header['Content-Length'] = strlen($content);
81 } 78 }
82 } 79 }
  80 + $header['Content-Type'] = 'image/'.$info['type'];
83 $img_type = $info['type']; 81 $img_type = $info['type'];
84 $content = base64_encode($content); 82 $content = base64_encode($content);
85 $img_base64 = 'data:image/' . $img_type . ';base64,' . $content; 83 $img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
86 - if($type != self::TYPE){  
87 - header('Content-Type: image/' . $img_type);  
88 - echo base64_decode($content);  
89 - exit;  
90 - }  
91 return response($img_base64,200,$header); 84 return response($img_base64,200,$header);
92 } 85 }
93 86
@@ -260,6 +260,6 @@ Route::group([], function () { @@ -260,6 +260,6 @@ Route::group([], function () {
260 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); 260 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
261 // Route::any('/', [\App\Http\Controllers\Bside\ComController::class, 'get_country'])->name('get_country'); 261 // Route::any('/', [\App\Http\Controllers\Bside\ComController::class, 'get_country'])->name('get_country');
262 Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download'); 262 Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download');
263 - Route::any('/image/{hash}/{type?}/{w?}/{h?}', [\App\Http\Controllers\file\ImageController::class,'index'])->name('image_show'); 263 + Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\file\ImageController::class,'index'])->name('image_show');
264 Route::any('/file_hash/{hash}/', [\App\Http\Controllers\file\FileController::class,'index'])->name('file_show'); 264 Route::any('/file_hash/{hash}/', [\App\Http\Controllers\file\FileController::class,'index'])->name('file_show');
265 }); 265 });