|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Repository\AssetRepository; |
|
8
|
|
|
use Chamilo\CoreBundle\Traits\ControllerTrait; |
|
9
|
|
|
use Chamilo\CoreBundle\Traits\CourseControllerTrait; |
|
10
|
|
|
use Chamilo\CoreBundle\Traits\ResourceControllerTrait; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
|
13
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @Route("/assets") |
|
17
|
|
|
*/ |
|
18
|
|
|
class AssetController |
|
19
|
|
|
{ |
|
20
|
|
|
use CourseControllerTrait; |
|
21
|
|
|
use ResourceControllerTrait; |
|
|
|
|
|
|
22
|
|
|
use ControllerTrait; |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @Route("/{category}/{path}", methods={"GET"}, requirements={"path"=".+"}) |
|
26
|
|
|
*/ |
|
27
|
|
|
public function showFile($category, $path, AssetRepository $assetRepository) |
|
28
|
|
|
{ |
|
29
|
|
|
$filePath = $category.'/'.$path; |
|
30
|
|
|
$has = $assetRepository->getFileSystem()->has($filePath); |
|
31
|
|
|
if ($has) { |
|
32
|
|
|
$fileName = basename($filePath); |
|
33
|
|
|
$stream = $assetRepository->getFileSystem()->readStream($filePath); |
|
34
|
|
|
|
|
35
|
|
|
$response = new StreamedResponse( |
|
36
|
|
|
function () use ($stream): void { |
|
37
|
|
|
stream_copy_to_stream($stream, fopen('php://output', 'wb')); |
|
38
|
|
|
} |
|
39
|
|
|
); |
|
40
|
|
|
$disposition = $response->headers->makeDisposition( |
|
41
|
|
|
ResponseHeaderBag::DISPOSITION_INLINE, |
|
42
|
|
|
$fileName |
|
43
|
|
|
); |
|
44
|
|
|
$response->headers->set('Content-Disposition', $disposition); |
|
45
|
|
|
//$response->headers->set('Content-Type', $mimeType ?: 'application/octet-stream'); |
|
46
|
|
|
|
|
47
|
|
|
return $response; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|