src/Phlexible/Bundle/FrontendMediaBundle/Controller/MediaController.php
public function downloadAction($fileId)
    {
        $volumeManager = $this->get('phlexible_media_manager.volume_manager');

        try {
            $volume = $volumeManager->getByFileId($fileId);
        } catch (\Exception $e) {
            throw $this->createNotFoundException($e->getMessage(), $e);
        }

        // TODO get lates file version
        $file = $volume->findFile($fileId);

        $filePath = $file->getPhysicalPath();

        if (!file_exists($filePath)) {
            throw $this->createNotFoundException('File not found.');
        }

        $mimeType = $file->getMimeType();

        $response = new BinaryFileResponse($filePath, 200, array('Content-Type' => $mimeType));
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $file->getName());

        return $response;
    }
public function downloadAction($fileId)
    {
        $volumeManager = $this->get('phlexible_media_manager.volume_manager');

        try {
            $volume = $volumeManager->getByFileId($fileId);
        } catch (\Exception $e) {
            throw $this->createNotFoundException($e->getMessage(), $e);
        }

        // TODO get lates file version
        $file = $volume->findFile($fileId);

        $filePath = $file->getPhysicalPath();

        if (!file_exists($filePath)) {
            throw $this->createNotFoundException('File not found.');
        }

        $mimeType = $file->getMimeType();

        $response = new BinaryFileResponse($filePath, 200, array('Content-Type' => $mimeType));
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $file->getName());

        return $response;
    }
public function downloadAction ( $ fileId ) { $ volumeManager = $ this -> get ( 'phlexible_media_manager.volume_manager' ) ; try { $ volume = $ volumeManager -> getByFileId ( $ fileId ) ; } catch ( \ Exception $ e ) { throw $ this -> createNotFoundException ( $ e -> getMessage ( ) , $ e ) ; } // TODO get lates file version $ file = $ volume -> findFile ( $ fileId ) ; $ filePath = $ file -> getPhysicalPath ( ) ; if ( ! file_exists ( $ filePath ) ) { throw $ this -> createNotFoundException ( 'File not found.' ) ; } $ mimeType = $ file -> getMimeType ( ) ; $ response = new BinaryFileResponse ( $ filePath , 200 , array ( 'Content-Type' => $ mimeType ) ) ; $ response -> setContentDisposition ( ResponseHeaderBag :: DISPOSITION_ATTACHMENT , $ file -> getName ( ) ) ; return $ response ; }
Download a media file.

@param string $fileId

@return Response
@Route("/download/{fileId}", name="frontendmedia_download")
Download a media file .