Conditions | 4 |
Paths | 4 |
Total Lines | 19 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | public function __invoke($fileId, $filename) |
||
18 | { |
||
19 | // Verify file ID and filename match |
||
20 | $file = FileUploads::where('file_id', $fileId)->where('file_name', $filename)->firstOrFail(); |
||
21 | |||
22 | // If file is not being downloaded by user, verify file is public accessable |
||
23 | if(!Auth::check() && !$file->public) |
||
24 | { |
||
25 | abort(403, 'You do not have permission to download this file'); |
||
26 | } |
||
27 | |||
28 | // Verify that the file is in place |
||
29 | if(!Storage::disk($file->disk)->exists($file->folder.DIRECTORY_SEPARATOR.$file->file_name)) |
||
30 | { |
||
31 | abort(404, 'Unable to find the file specified'); |
||
32 | } |
||
33 | |||
34 | event(new DownloadedFileEvent($file)); |
||
35 | return Storage::disk($file->disk)->download($file->folder.DIRECTORY_SEPARATOR.$file->file_name); |
||
36 | } |
||
38 |