function file_get_content_headers

Same name in other branches
  1. 7.x includes/file.inc \file_get_content_headers()
  2. 9 core/modules/file/file.module \file_get_content_headers()
  3. 8.9.x core/modules/file/file.module \file_get_content_headers()
  4. 10 core/modules/file/file.module \file_get_content_headers()

Examines a file entity and returns appropriate content headers for download.

Parameters

\Drupal\file\FileInterface $file: A file entity.

Return value

array An associative array of headers, as expected by \Symfony\Component\HttpFoundation\StreamedResponse.

3 calls to file_get_content_headers()
EditorHooks::fileDownload in core/modules/editor/src/Hook/EditorHooks.php
Implements hook_file_download().
FileDownloadHook::__invoke in core/modules/file/src/Hook/FileDownloadHook.php
Implements hook_file_download().
FileTestHooks::fileDownload in core/modules/file/tests/file_test/src/Hook/FileTestHooks.php
Implements hook_file_download().

File

core/modules/file/file.module, line 39

Code

function file_get_content_headers(FileInterface $file) {
    return [
        'Content-Type' => $file->getMimeType(),
        'Content-Length' => $file->getSize(),
        'Cache-Control' => 'private',
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.