In some situations when youâ€™re creating a web page with links to a file like pdf â€“ xml â€“ jpeg , or other external program file , you may want userâ€™s browser prompt to download the file instead of opening it in the browser window or in an external program . There are a few different methods you can do this , my favorite is PHP-based . Start by creating a new file on your server or on your development computer called download.php and paste the below code into the file .
Complete article : http://tournasdimitrios1.wordpress.com/2012/01/10/how-to-make-files-downloadable-with-php/
// download.php
if (isset($_GET['file'])) {
//$file = $_GET['file'];
$file = filter_input(INPUT_GET, 'file', FILTER_SANITIZE_ENCODED);
if (file_exists($file) && is_readable($file) && preg_match('/\.pdf$/',$file)) {
header('Content-Description: File Transfer');
header('Content-type: application/pdf');
header("Content-Type: application/force-download");// some browsers need this
header("Content-Disposition: attachment; filename=\"$file\"");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file2));
ob_clean();
flush();
readfile($file);
exit;
}else {
header("HTTP/1.0 404 Not Found");
echo "