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