Conditions | 2 |
Paths | 2 |
Total Lines | 13 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 6 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | public function download(string $path) |
||
14 | { |
||
15 | $projectDir = $this->get('kernel')->getProjectDir(); |
||
16 | $pathToFile = $projectDir.'/media/'.substr(str_replace('..', '', $path), \strlen('media/')); |
||
17 | |||
18 | if (! file_exists($pathToFile)) { |
||
19 | throw $this->createNotFoundException('The media does not exist...'); |
||
20 | } |
||
21 | |||
22 | $response = new BinaryFileResponse($pathToFile); |
||
23 | $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT); |
||
24 | |||
25 | return $response; |
||
26 | } |
||
28 |