src/TrivialSense/FrameworkCommon/Controller/AbstractController.php
public function sendFile($filePath, $fileName = null)
    {
        if ($filePath instanceof File) {
            $filePath = $filePath->getPathname();
        }

        $response = new Response();
        $response->headers->set('Cache-Control', 'private');
        $response->headers->set('Content-Type', mime_content_type($filePath));
        $response->headers->set('Content-Disposition', 'attachment;filename="' . ($fileName ?: basename($filePath)). '"');
        $response->headers->set('Content-Length', filesize($filePath));

        $response->setContent(file_get_contents($filePath));

        return $response;
    }
public function sendFile($filePath, $fileName = null)
    {
        if ($filePath instanceof File) {
            $filePath = $filePath->getPathname();
        }

        $response = new Response();
        $response->headers->set('Cache-Control', 'private');
        $response->headers->set('Content-Type', mime_content_type($filePath));
        $response->headers->set('Content-Disposition', 'attachment;filename="' . ($fileName ?: basename($filePath)). '"');
        $response->headers->set('Content-Length', filesize($filePath));

        $response->setContent(file_get_contents($filePath));

        return $response;
    }
public function sendFile ( $ filePath , $ fileName = null ) { if ( $ filePath instanceof File ) { $ filePath = $ filePath -> getPathname ( ) ; } $ response = new Response ( ) ; $ response -> headers -> set ( 'Cache-Control' , 'private' ) ; $ response -> headers -> set ( 'Content-Type' , mime_content_type ( $ filePath ) ) ; $ response -> headers -> set ( 'Content-Disposition' , 'attachment;filename="' . ( $ fileName ? : basename ( $ filePath ) ) . '"' ) ; $ response -> headers -> set ( 'Content-Length' , filesize ( $ filePath ) ) ; $ response -> setContent ( file_get_contents ( $ filePath ) ) ; return $ response ; }
Sends a Response serving a given file

@param $filePath
@param string $fileName Custom name, to replace original one

@return Response
Sends a Response serving a given file