09 Feb, 2007
Force File Download
Posted by: Jennifer In: Bookmarks|PHP Related|Script snippet|Scripts
How to force a file to download (without having to zip it up).
$filename = "secure/writeToFile.doc";
header("Content-Length: " . filesize($filename));
header('Content-Type: application/msword');
header('Content-Disposition: attachment; filename=writeToFile.doc');
readfile($filename);
a few other content types – lots more at the above link…
"pdf": "application/pdf"
"zip": "application/zip"
"xls": "application/vnd.ms-excel"
"ppt": "application/vnd.ms-powerpoint"
"gif": "image/gif"
"png": "image/png"
"jpg": "image/jpg"
"mp3": "audio/mpeg"
"mp3": "audio/mp3"
"wav": "audio/x-wav"
"mpe": "video/mpeg"
"mov": "video/quicktime"
"avi": "video/x-msvideo"