I looked at the code I use and this is a site that I have listed in my notes:
http://w-shadow.com/blog/2007/08/12/how-to-force-file-download-with-php/comment-page-1/. It talks about turning off the zlib.output_compression.
// like this:
if ( ini_get('zlib.output_compression') ) {
ini_set('zlib.output_compression', 'Off');
}
I think you also need to define your content type correctly. Make sure that no other headers are going out first of that you have white space(extra lines before the php) in your file. This is the rest of the code I use:
$file_type_array = array(
# documents
'doc' =>'application/msword',
'docx' =>'application/msword',
//'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'rtf' => 'application/rtf',
'txt' => 'text/plain',
'pdf' => 'application/pdf',
# powerpoint
'pot' => 'application/mspowerpoint',
'pps' => 'application/mspowerpoint',
'ppt' => 'application/mspowerpoint',
'ppz' => 'application/mspowerpoint',
# excel
'csv' => 'application/x-msdownload',
'xlc' => 'application/vnd.ms-excel',
'xls' => 'application/vnd.ms-excel',
# web images
'gif' => 'image/gif',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'png' => 'image/png',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
# web files
'css' => 'text/css',
'htm' => 'text/html',
'html' => 'text/html',
'xml' => 'text/xml',
'js' => 'application/x-javascript',
# video
'avi' => 'video/x-msvideo',
'dl' => 'video/dl',
'fli' => 'video/fli',
'fli' => 'video/x-fli',
'flv' => 'video/flv',
'gl' => 'video/gl',
'mp2' => 'video/mpeg',
'mpe' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mov' => 'video/quicktime',
'qt' => 'video/quicktime',
'viv' => 'video/vnd.vivo',
'vivo' => 'video/vnd.vivo',
'wmv' => 'video/x-ms-wmv',
'wmx' => 'video/x-ms-wmx',
'wvx' => 'video/x-ms-wvx',
'asf' => 'video/x-ms-asf',
'asx' => 'video/x-ms-asx',
'movie' => 'video/x-sgi-movie'
);
$content_type = $file_type_array[$file_ext];
$filesize = filesize($filename);
if( is_file($filename) ){
if ( $filesize ) {
header('Content-Type: ' . $content_type);
header('Content-Disposition: attachment; filename="'.str_replace(' ','_',$display_filename).'.'.$file_ext.'"');
header("Content-Transfer-Encoding: binary");
header('Accept-Ranges: bytes');
// The three lines below basically make the download non-cacheable
header("Cache-control: private");
header('Pragma: private');
$time = gmdate('D, d M Y H:i:s', filectime($filename));
header('Last-Modified: '.$time.' EST');
//header("Expires: ".$time." EST");
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // date in the past
header('Content-Length: '.$filesize);
}
/* Read It */
$contents = fread(fopen($filename, "rb"), filesize($filename));
/* Print It */
echo $contents;
}