Skip to content

Instantly share code, notes, and snippets.

@alancoleman
Created October 1, 2013 14:19
Show Gist options
  • Save alancoleman/6779227 to your computer and use it in GitHub Desktop.
Save alancoleman/6779227 to your computer and use it in GitHub Desktop.
Basic PHP File download
<?php
$file = '/tmp/file.xml';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment