Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. BinaryFileResponse.php

function BinaryFileResponse::setFile

Sets the file to stream.

Return value

$this

Throws

FileException

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

File

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

Class

BinaryFileResponse
BinaryFileResponse represents an HTTP response delivering a file.

Namespace

Symfony\Component\HttpFoundation

Code

public function setFile(\SplFileInfo|string $file, ?string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true) : static {
    $isTemporaryFile = $file instanceof \SplTempFileObject;
    $this->tempFileObject = $isTemporaryFile ? $file : null;
    if (!$file instanceof File) {
        if ($file instanceof \SplFileInfo) {
            $file = new File($file->getPathname(), !$isTemporaryFile);
        }
        else {
            $file = new File($file);
        }
    }
    if (!$file->isReadable() && !$isTemporaryFile) {
        throw new FileException('File must be readable.');
    }
    $this->file = $file;
    if ($autoEtag) {
        $this->setAutoEtag();
    }
    if ($autoLastModified && !$isTemporaryFile) {
        $this->setAutoLastModified();
    }
    if ($contentDisposition) {
        $this->setContentDisposition($contentDisposition);
    }
    return $this;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal