TYPO3/Extbase/FAL/FalUtility.php
public static function downloadFile($fileUid, $additionalHeaders = array())
    {
        $fileRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
        $entity = $fileRepository->findByUid($fileUid);

        if (!$entity) {
            return false;
        }

        $properties = $entity->getProperties();

        $headers = array(
            'Pragma'                    => 'public',
            'Expires'                   => 0,
            'Cache-Control'             => 'must-revalidate, post-check=0, pre-check=0',
            'Cache-Control'             => 'public',
            'Content-Description'       => 'File Transfer',
            'Content-Type'              => $properties['mime_type'],
            'Content-Disposition'       => 'attachment; filename="' . $entity->getName() . '"',
            'Content-Transfer-Encoding' => 'binary',
            'Content-Length'            => $properties['size'],
        );

        if (!empty($additionalHeaders)) {
            array_merge($headers, $additionalHeaders);
        }

        try {
            $response = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response');

            foreach ($headers as $header => $data) {
                $response->setHeader($header, $data);
            }
            $response->sendHeaders();
            echo $entity->getContents();
            exit;
        } catch (Exception $e) {
            return $e;
        }
    }
public static function downloadFile($fileUid, $additionalHeaders = array())
    {
        $fileRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
        $entity = $fileRepository->findByUid($fileUid);

        if (!$entity) {
            return false;
        }

        $properties = $entity->getProperties();

        $headers = array(
            'Pragma'                    => 'public',
            'Expires'                   => 0,
            'Cache-Control'             => 'must-revalidate, post-check=0, pre-check=0',
            'Cache-Control'             => 'public',
            'Content-Description'       => 'File Transfer',
            'Content-Type'              => $properties['mime_type'],
            'Content-Disposition'       => 'attachment; filename="' . $entity->getName() . '"',
            'Content-Transfer-Encoding' => 'binary',
            'Content-Length'            => $properties['size'],
        );

        if (!empty($additionalHeaders)) {
            array_merge($headers, $additionalHeaders);
        }

        try {
            $response = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response');

            foreach ($headers as $header => $data) {
                $response->setHeader($header, $data);
            }
            $response->sendHeaders();
            echo $entity->getContents();
            exit;
        } catch (Exception $e) {
            return $e;
        }
    }
public static function downloadFile ( $ fileUid , $ additionalHeaders = array ( ) ) { $ fileRepository = GeneralUtility :: makeInstance ( 'TYPO3\\CMS\\Core\\Resource\\FileRepository' ) ; $ entity = $ fileRepository -> findByUid ( $ fileUid ) ; if ( ! $ entity ) { return false ; } $ properties = $ entity -> getProperties ( ) ; $ headers = array ( 'Pragma' => 'public' , 'Expires' => 0 , 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0' , 'Cache-Control' => 'public' , 'Content-Description' => 'File Transfer' , 'Content-Type' => $ properties [ 'mime_type' ] , 'Content-Disposition' => 'attachment; filename="' . $ entity -> getName ( ) . '"' , 'Content-Transfer-Encoding' => 'binary' , 'Content-Length' => $ properties [ 'size' ] , ) ; if ( ! empty ( $ additionalHeaders ) ) { array_merge ( $ headers , $ additionalHeaders ) ; } try { $ response = GeneralUtility :: makeInstance ( 'TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response' ) ; foreach ( $ headers as $ header => $ data ) { $ response -> setHeader ( $ header , $ data ) ; } $ response -> sendHeaders ( ) ; echo $ entity -> getContents ( ) ; exit ; } catch ( Exception $ e ) { return $ e ; } }
Download a FAL-File

@param $fileUid
@param array $additionalHeaders
@return bool|\Exception|Exception
Download a FAL - File