Symfony\Bundle\FrameworkBundle\Controller\Controller::file PHP Method

file() protected method

Returns a BinaryFileResponse object with original or customized file name and disposition header.
protected file ( SplFileInfo | string $file, string | null $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT ) : BinaryFileResponse
$file SplFileInfo | string File object or path to file to be sent as response
$fileName string | null File name to be sent to response or null (will use original file name)
$disposition string Disposition of response ("attachment" is default, other type is "inline")
return Symfony\Component\HttpFoundation\BinaryFileResponse
    protected function file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT)
    {
        $response = new BinaryFileResponse($file);
        $response->setContentDisposition($disposition, $fileName === null ? $response->getFile()->getFilename() : $fileName);
        return $response;
    }

Usage Example

Esempio n. 1
0
 public function file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT)
 {
     return parent::file($file, $fileName, $disposition);
 }