W3cubDocs

/Drupal 8

function file_get_content_headers

file_get_content_headers(FileInterface $file)

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.

File

core/modules/file/file.module, line 544
Defines a "managed_file" Form API field and a "file" field for Field module.

Code

function file_get_content_headers(FileInterface $file) {
  $type = Unicode::mimeHeaderEncode($file->getMimeType());

  return array(
    'Content-Type' => $type,
    'Content-Length' => $file->getSize(),
    'Cache-Control' => 'private',
  );
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!file!file.module/function/file_get_content_headers/8.1.x