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 552
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',
  );
}
doc_Drupal
2016-10-29 09:14:11
Comments
Leave a Comment

Please login to continue.