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

Breadcrumb

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

function BinaryFileResponse::sendContent

Overrides Response::sendContent

File

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

Class

BinaryFileResponse
BinaryFileResponse represents an HTTP response delivering a file.

Namespace

Symfony\Component\HttpFoundation

Code

public function sendContent() : static {
    try {
        if (!$this->isSuccessful()) {
            return $this;
        }
        if (0 === $this->maxlen) {
            return $this;
        }
        $out = fopen('php://output', 'w');
        if ($this->tempFileObject) {
            $file = $this->tempFileObject;
            $file->rewind();
        }
        else {
            $file = new \SplFileObject($this->file
                ->getPathname(), 'r');
        }
        ignore_user_abort(true);
        if (0 !== $this->offset) {
            $file->fseek($this->offset);
        }
        $length = $this->maxlen;
        while ($length && !$file->eof()) {
            $read = $length > $this->chunkSize || 0 > $length ? $this->chunkSize : $length;
            if (false === ($data = $file->fread($read))) {
                break;
            }
            while ('' !== $data) {
                $read = fwrite($out, $data);
                if (false === $read || connection_aborted()) {
                    break 2;
                }
                if (0 < $length) {
                    $length -= $read;
                }
                $data = substr($data, $read);
            }
        }
        fclose($out);
    } finally {
        if (null === $this->tempFileObject && $this->deleteFileAfterSend && is_file($this->file
            ->getPathname())) {
            unlink($this->file
                ->getPathname());
        }
    }
    return $this;
}

API Navigation

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