Symfony\Component\HttpFoundation\BinaryFileResponse::setFile PHP Method

setFile() public method

Sets the file to stream.
public setFile ( SplFileInfo | string $file, string $contentDisposition = null, boolean $autoEtag = false, boolean $autoLastModified = true ) : BinaryFileResponse
$file SplFileInfo | string The file to stream
$contentDisposition string
$autoEtag boolean
$autoLastModified boolean
return BinaryFileResponse
    public function setFile($file, $contentDisposition = null, $autoEtag = false, $autoLastModified = true)
    {
        if (!$file instanceof File) {
            if ($file instanceof \SplFileInfo) {
                $file = new File($file->getPathname());
            } else {
                $file = new File((string) $file);
            }
        }
        if (!$file->isReadable()) {
            throw new FileException('File must be readable.');
        }
        $this->file = $file;
        if ($autoEtag) {
            $this->setAutoEtag();
        }
        if ($autoLastModified) {
            $this->setAutoLastModified();
        }
        if ($contentDisposition) {
            $this->setContentDisposition($contentDisposition);
        }
        return $this;
    }

Usage Example

 public function setFile($file, $contentDisposition = null, $autoEtag = false, $autoLastModified = true)
 {
     parent::setFile($file, $contentDisposition, $autoEtag, $autoLastModified);
     $this->prepend = 'hljs.registerLanguage("' . $this->file->getBasename('.' . $this->file->getExtension()) . '", ';
     $this->append = ');';
     return $this;
 }
All Usage Examples Of Symfony\Component\HttpFoundation\BinaryFileResponse::setFile