正在显示
1 个修改的文件
包含
23 行增加
和
3 行删除
| @@ -5,6 +5,7 @@ namespace App\Http\Controllers\File; | @@ -5,6 +5,7 @@ namespace App\Http\Controllers\File; | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Controllers\Controller; | 6 | use App\Http\Controllers\Controller; |
| 7 | use App\Http\Controllers\type; | 7 | use App\Http\Controllers\type; |
| 8 | +use App\Models\File\File; | ||
| 8 | use App\Models\File\Image as ImageModel; | 9 | use App\Models\File\Image as ImageModel; |
| 9 | use App\Models\Project\Project; | 10 | use App\Models\Project\Project; |
| 10 | use App\Services\CosService; | 11 | use App\Services\CosService; |
| @@ -257,9 +258,28 @@ class ImageController extends Controller | @@ -257,9 +258,28 @@ class ImageController extends Controller | ||
| 257 | * @method :post | 258 | * @method :post |
| 258 | * @time :2023/7/19 17:59 | 259 | * @time :2023/7/19 17:59 |
| 259 | */ | 260 | */ |
| 260 | - public function download($filename){ | ||
| 261 | - $path = Storage::path($filename); | ||
| 262 | - return response()->download($path,time().rand(1,100000)); | 261 | + public function download(){ |
| 262 | + $imageModel = new Image(); | ||
| 263 | + $info = $imageModel->read(['hash' => $this->param['hash']]); | ||
| 264 | + if ($info === false) { | ||
| 265 | + $this->response('指定文件不存在!', Code::USER_ERROR); | ||
| 266 | + } | ||
| 267 | + if($info['is_cos'] == 1){ | ||
| 268 | + $cos = new CosService(); | ||
| 269 | + $fileUrl = $cos->getImageUrl($info['path']); | ||
| 270 | + }else{ | ||
| 271 | + $fileUrl = $this->config['root'].$info['path']; | ||
| 272 | + if (!is_file($fileUrl)) { | ||
| 273 | + $this->response('指定图片已被系统删除!', Code::USER_ERROR); | ||
| 274 | + } | ||
| 275 | + } | ||
| 276 | + $fileName = basename($info['path']); // 要保存的文件名 | ||
| 277 | + // 设置响应头 | ||
| 278 | + header('Content-Description: File Transfer'); | ||
| 279 | + header('Content-Type: application/octet-stream'); | ||
| 280 | + header('Content-Disposition: attachment; filename="' . $fileName . '"'); | ||
| 281 | + // 下载文件 | ||
| 282 | + readfile($fileUrl); | ||
| 263 | } | 283 | } |
| 264 | 284 | ||
| 265 | /** | 285 | /** |
-
请 注册 或 登录 后发表评论