/** * Output the right headers for outputting file data to a browser. * * @param \GO\Base\Fs\File $file Use \GO\Base\Fs\MemoryFile for outputting variables * @param boolean $inline * @param boolean $cache Cache the file for one day in the browser. * @param array $extraHeaders Key value array for extra headers */ public static function outputDownloadHeaders(\GO\Base\Fs\File $file, $inline = true, $cache = false, $extraHeaders = array()) { header('Content-Transfer-Encoding: binary'); $disposition = $inline ? 'inline' : 'attachment'; if ($cache) { header("Expires: " . date("D, j M Y G:i:s ", time() + 86400) . 'GMT'); //expires in 1 day header('Cache-Control: cache'); header('Pragma: cache'); } if (Http::isInternetExplorer()) { header('Content-Type: application/download'); header('Content-Disposition: ' . $disposition . '; filename="' . rawurlencode($file->name()) . '"'); if (!$cache) { header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } } else { header('Content-Type: ' . $file->mimeType()); header('Content-Disposition: ' . $disposition . '; filename="' . $file->name() . '"'); if (!$cache) { header('Pragma: no-cache'); } } if ($file->exists()) { if ($file->extension() != 'zip') { //Don't set content lenght for zip files because gzip of apache will corrupt the download. http://www.heath-whyte.info/david/computers/corrupted-zip-file-downloads-with-php header('Content-Length: ' . $file->size()); } header("Last-Modified: " . gmdate("D, d M Y H:i:s", $file->mtime()) . " GMT"); header("ETag: " . $file->md5Hash()); } foreach ($extraHeaders as $header => $value) { header($header . ': ' . $value); } }