一些诸如 jpg,mp3 类型的文件,通常会在客户端浏览器中直接被播放或使用。如果你希望它们强制被下载,可以使用以下代码:

function forceDownload($file)
{ 
    $file_name = $file; 
    $mime = 'application/force-download'; 
    header('Pragma: public');     // required 
    header('Expires: 0');        // no cache 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header('Cache-Control: private',false); 
    header('Content-Type: '.$mime); 
    header('Content-Disposition: attachment; filename="'.basename($file_name).'"'); 
    header('Content-Transfer-Encoding: binary'); 
    header('Connection: close'); 
    readfile($file_name);        // push it out 
    exit(); 
}