Example #1
0
 /**
  * Outputs file Contents,
  * clears output buffer first and sends headers accordingly.
  *
  * @param FileInterface $file
  * @param bool $asDownload If set Content-Disposition attachment is sent, inline otherwise
  * @param string $alternativeFilename the filename for the download (if $asDownload is set)
  * @return void
  */
 public function dumpFileContents(FileInterface $file, $asDownload = FALSE, $alternativeFilename = NULL)
 {
     $downloadName = $alternativeFilename ?: $file->getName();
     $contentDisposition = $asDownload ? 'attachment' : 'inline';
     header('Content-Disposition: ' . $contentDisposition . '; filename="' . $downloadName . '"');
     header('Content-Type: ' . $file->getMimeType());
     header('Content-Length: ' . $file->getSize());
     // Cache-Control header is needed here to solve an issue with browser IE8 and lower
     // See for more information: http://support.microsoft.com/kb/323308
     header("Cache-Control: ''");
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', array_pop($this->driver->getFileInfoByIdentifier($file->getIdentifier(), array('mtime')))) . ' GMT', TRUE, 200);
     ob_clean();
     flush();
     $this->driver->dumpFileContents($file->getIdentifier());
 }