Skip to content

Instantly share code, notes, and snippets.

@henrikbjorn
Forked from tcarlsen/gist:451192
Created June 24, 2010 09:13
Show Gist options
  • Save henrikbjorn/451210 to your computer and use it in GitHub Desktop.
Save henrikbjorn/451210 to your computer and use it in GitHub Desktop.
<?php
class DownloaderComponent extends Object
{
public function sendFileHeaders($path)
{
$handle = finfo_open(FILEINFO_MIME_TYPE);
$contentType = finfo_file($handle, $path);
$extension = path_info($path, PATHINFO_EXTENSION); //Better way to get the extension
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $contenttype");
header("Content-Disposition: attachment; filename=\"" . basename($path) . "\";");
header("Content-Transfer-Encoding: binary");
readfile($path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment