mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-20 14:10:11 -07:00
45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace AppBundle\Controller;
|
|
|
|
use AppBundle\Entity\LDraw\Model;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
/**
|
|
* @Route("/files")
|
|
*/
|
|
class MediaController extends Controller
|
|
{
|
|
/**
|
|
* @Route("/{path}", name="media_file", requirements={"path"=".+"})
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function stlAction($path)
|
|
{
|
|
$mediaFilesystem = $this->get('oneup_flysystem.media_filesystem');
|
|
|
|
if ($mediaFilesystem->has($path)) {
|
|
$response = new BinaryFileResponse($mediaFilesystem->getAdapter()->getPathPrefix().DIRECTORY_SEPARATOR.$path);
|
|
$response->headers->set('Content-Type', $mediaFilesystem->getMimetype($path));
|
|
|
|
// Create the disposition of the file
|
|
$disposition = $response->headers->makeDisposition(
|
|
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
|
|
basename($path)
|
|
);
|
|
|
|
$response->headers->set('Content-Disposition', $disposition);
|
|
|
|
return $response;
|
|
}
|
|
throw new FileNotFoundException($path);
|
|
}
|
|
}
|