正在显示
1 个修改的文件
包含
26 行增加
和
0 行删除
| @@ -267,4 +267,30 @@ class FileController | @@ -267,4 +267,30 @@ class FileController | ||
| 267 | } | 267 | } |
| 268 | return $data; | 268 | return $data; |
| 269 | } | 269 | } |
| 270 | + | ||
| 271 | + /** | ||
| 272 | + * @remark :文件下载 | ||
| 273 | + * @name :downLoad | ||
| 274 | + * @author :lyh | ||
| 275 | + * @method :post | ||
| 276 | + * @time :2023/6/26 16:28 | ||
| 277 | + */ | ||
| 278 | + public function downLoad($hash){ | ||
| 279 | + $file_model = new File(); | ||
| 280 | + $info = $file_model->read(['hash' => $hash]); | ||
| 281 | + if ($info === false) { | ||
| 282 | + $this->response('指定文件不存在!', Code::USER_ERROR); | ||
| 283 | + } | ||
| 284 | + $path = $info['path']; | ||
| 285 | + if (!is_file($path)) { | ||
| 286 | + $this->response('指定文件已被系统删除!', Code::USER_ERROR); | ||
| 287 | + } | ||
| 288 | + $fileUrl = url('public/upload/files/'.basename($path)); // 文件的 URL | ||
| 289 | + $fileName = 'downloaded_file'.'.'.$info['type']; // 要保存的文件名 | ||
| 290 | + // 设置响应头 | ||
| 291 | + header('Content-Type: application/octet-stream'); | ||
| 292 | + header('Content-Disposition: attachment; filename="' . $fileName . '"'); | ||
| 293 | + // 下载文件 | ||
| 294 | + readfile($fileUrl); | ||
| 295 | + } | ||
| 270 | } | 296 | } |
-
请 注册 或 登录 后发表评论