pomińmy to, że zależy to również od ustawień przeglądarki użytkownika, ja używałem taki kod:
<?php
@header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); @header('Cache-Control: private', false); @header('Content-Type: '.allow_file
($rozszerzenie_pliku, 'application/force-download')); @header('Content-Disposition: attachment; filename=xyz'); @header('Content-Transfer-Encoding: binary'); @header('Content-Length: jakas_liczba'); // wielkość pliku w bajtach @header('Accept-Ranges: bytes'); // dlatego w bajtach ^^
@readfile('nazwa_pliku_ktory_chcemy_wyslac');
?>
gdzie zamiast fukcji allow_file możesz dać po prostu odpowiedni mime-type pliku; przykład tej funkcji:
<?php
function allow_file($ex, $mtype = false)
{
if ($ex == 'zip')
$mtype = 'application/x-zip-compressed';
elseif ($ex == 'rar')
$mtype = 'application/x-rar-compressed';
elseif ($ex == 'tar')
$mtype = 'application/x-tar';
elseif ($ex == 'rpm')
$mtype = 'audio/x-pn-realaudio-plugin';
elseif ($ex == 'mp3' || $ex == 'mpeg' || $ex == 'mpg' || $ex == 'mpe')
$mtype = 'audio/mpeg';
elseif ($ex == 'wav')
$mtype = 'audio/x-wav';
elseif ($ex == 'avi')
$mtype = 'video/x-msvideo';
elseif ($ex == 'pdf')
$mtype = 'application/pdf';
elseif ($ex == 'doc')
$mtype = 'application/msword';
elseif ($ex == 'wri')
$mtype = 'application/mswrite';
elseif ($ex == 'rtf')
$mtype = 'application/rtf';
elseif ($ex == 'swf')
$mtype = 'application/x-shockwave-flash';
elseif ($ex == 'sql')
$mtype = 'application/force-download';
elseif ($ex == 'gz' || $ex == 'gzip')
$mtype = 'application/x-gzip';
elseif ($ex == 'ppt')
$mtype = 'application/vnd.ms-powerpoint';
elseif ($ex == 'asf' || $ex == 'asx')
$mtype = 'audio/x-ms-asf';
elseif ($ex == 'wax')
$mtype = 'audio/x-ms-wax';
elseif ($ex == 'wm')
$mtype = 'audio/x-ms-wm';
elseif ($ex == 'wma')
$mtype = 'audio/x-ms-wma';
elseif ($ex == 'wmv')
$mtype = 'audio/x-ms-wmv';
elseif ($ex == 'wvx')
$mtype = 'audio/x-ms-wvx';
elseif ($ex == 'mov' || $ex == 'qt')
$mtype = 'video/quicktime';
elseif ($ex == 'spl')
$mtype = 'application/futuresplash';
elseif (ereg('^(exe|com|bin|cgi|bat|pif|scr)$', $ex)) $mtype = 'application/octet-stream';
elseif (ereg('^xl(s|a|b|c|d|k|l|m|v|w)$', $ex)) $mtype = 'application/vnd.ms-excel';
return($mtype);
}
?>
Pozdrawiam!