You are here

public function BinaryFileResponse::setFile in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/BinaryFileResponse.php \Symfony\Component\HttpFoundation\BinaryFileResponse::setFile()

Sets the file to stream.

Parameters

\SplFileInfo|string $file The file to stream:

string $contentDisposition:

bool $autoEtag:

bool $autoLastModified:

Return value

BinaryFileResponse

Throws

FileException

1 call to BinaryFileResponse::setFile()
BinaryFileResponse::__construct in vendor/symfony/http-foundation/BinaryFileResponse.php
Constructor.

File

vendor/symfony/http-foundation/BinaryFileResponse.php, line 85

Class

BinaryFileResponse
BinaryFileResponse represents an HTTP response delivering a file.

Namespace

Symfony\Component\HttpFoundation

Code

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;
}