Skip to content

Instantly share code, notes, and snippets.

@shin1x1
Created November 11, 2010 17:03
Show Gist options
  • Save shin1x1/672807 to your computer and use it in GitHub Desktop.
Save shin1x1/672807 to your computer and use it in GitHub Desktop.
<?php
// authentication
if (!authentication()) {
exit;
}
$filepath = "/path/to/file";
$sizes = getimagesize($filepath);
if (!empty($sizes['mime'])) {
$mime = $sizes['mime'];
} else {
$mime = 'application/octet-stream';
}
header('Content-Type: '.$mime);
header('Content-Size: '.filesize($filepath));
readfile($filepath); // or fpassthru(fopen($filepath, 'rb'));
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment