Skip to content

Instantly share code, notes, and snippets.

@SmetDenis
Created August 17, 2015 15:18
Show Gist options
  • Save SmetDenis/0b7b04c9a6b0a88887e9 to your computer and use it in GitHub Desktop.
Save SmetDenis/0b7b04c9a6b0a88887e9 to your computer and use it in GitHub Desktop.
<?php
// no cache
if (!headers_sent()) {
header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
}
// download
if (!headers_sent()) {
// Required for some browsers
if (ini_get('zlib.output_compression')) {
@ini_set('zlib.output_compression', 'Off');
}
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
// Required for certain browsers
header('Cache-Control: private', false);
header('Content-Disposition: attachment; filename="' . basename(str_replace('"', '', $filename)) . '";');
header('Content-Type: application/force-download');
header('Content-Transfer-Encoding: binary');
if ($content) {
header('Content-Length: ' . strlen($content));
}
ob_clean();
flush();
if ($content) {
echo $content;
}
}
// utf8
if (!headers_sent()) {
header('Content-type: text/html; charset=utf-8');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment