|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the BenGorFile package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
|
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace BenGorFile\FileBundle\Controller; |
|
14
|
|
|
|
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse; |
|
18
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* File download controller. |
|
22
|
|
|
* |
|
23
|
|
|
* @author Beñat Espiña <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class DownloadController extends Controller |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Gets the file of given file name in the Gaufrette filesystem. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $filename The file name |
|
31
|
|
|
* @param string $uploadDestination The gaufrette filesystem |
|
32
|
|
|
* |
|
33
|
|
|
* @return BinaryFileResponse |
|
34
|
|
|
*/ |
|
35
|
|
|
public function gaufretteAction($filename, $uploadDestination) |
|
36
|
|
|
{ |
|
37
|
|
|
return new BinaryFileResponse('gaufrette://' . $uploadDestination . '/' . $filename); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Gets the file of given file name in the Symfony filesystem. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $filename The file name |
|
44
|
|
|
* @param string $uploadDestination The path of file storage |
|
45
|
|
|
* |
|
46
|
|
|
* @return BinaryFileResponse |
|
47
|
|
|
*/ |
|
48
|
|
|
public function symfonyAction($filename, $uploadDestination) |
|
49
|
|
|
{ |
|
50
|
|
|
try { |
|
51
|
|
|
return new BinaryFileResponse($uploadDestination . '/' . $filename); |
|
52
|
|
|
} catch (FileNotFoundException $exception) { |
|
53
|
|
|
throw new NotFoundHttpException(); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|