Conditions | 4 |
Paths | 4 |
Total Lines | 29 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 5.024 |
Changes | 0 |
1 | <?php namespace Distilleries\Expendable\Http\Controllers\Frontend; |
||
7 | 12 | public function getIndex($path = '') |
|
8 | { |
||
9 | |||
10 | 12 | $directory = explode('/', $path); |
|
11 | 12 | $directory = reset($directory); |
|
12 | 12 | $white_liste = config('expendable.folder_whitelist'); |
|
13 | 12 | if (in_array($directory, $white_liste)) |
|
14 | { |
||
15 | 9 | $path = storage_path($path); |
|
16 | 9 | $filesystem = app('files'); |
|
17 | 9 | if ($filesystem->isFile($path)) |
|
18 | { |
||
19 | 6 | $mimetype = mime_content_type($path); |
|
20 | 6 | if (@is_array(getimagesize($path))) |
|
21 | { |
||
22 | 3 | return response()->make($filesystem->get($path), 200, array('content-type' => $mimetype)); |
|
23 | } else |
||
24 | { |
||
25 | 3 | $name = explode('/', $path); |
|
26 | 3 | $name = end($name); |
|
27 | |||
28 | 3 | return response()->download($path, $name, array('content-type' => $mimetype)); |
|
29 | } |
||
30 | } |
||
31 | } |
||
32 | |||
33 | |||
34 | 6 | return abort(404); |
|
35 | } |
||
36 | } |