作者 lyh

gx

... ... @@ -5,6 +5,7 @@ namespace App\Http\Controllers\File;
use App\Enums\Common\Code;
use App\Http\Controllers\Controller;
use App\Http\Controllers\type;
use App\Models\File\File;
use App\Models\File\Image as ImageModel;
use App\Models\Project\Project;
use App\Services\CosService;
... ... @@ -257,9 +258,28 @@ class ImageController extends Controller
* @method :post
* @time :2023/7/19 17:59
*/
public function download($filename){
$path = Storage::path($filename);
return response()->download($path,time().rand(1,100000));
public function download(){
$imageModel = new Image();
$info = $imageModel->read(['hash' => $this->param['hash']]);
if ($info === false) {
$this->response('指定文件不存在!', Code::USER_ERROR);
}
if($info['is_cos'] == 1){
$cos = new CosService();
$fileUrl = $cos->getImageUrl($info['path']);
}else{
$fileUrl = $this->config['root'].$info['path'];
if (!is_file($fileUrl)) {
$this->response('指定图片已被系统删除!', Code::USER_ERROR);
}
}
$fileName = basename($info['path']); // 要保存的文件名
// 设置响应头
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
// 下载文件
readfile($fileUrl);
}
/**
... ...