-1
當我下載一個文件,如MP3 extention,FLV等它會下載它現在開始緩衝,當我從它下載文件中刪除extention ...下載從本地主機站點文件在PHP
可以請你告訴什麼背後的問題......
要下載的文件是=> theangelfoundation-12-5-2012-09-17-27-somebody.mp3
在此先感謝..
當我下載一個文件,如MP3 extention,FLV等它會下載它現在開始緩衝,當我從它下載文件中刪除extention ...下載從本地主機站點文件在PHP
可以請你告訴什麼背後的問題......
要下載的文件是=> theangelfoundation-12-5-2012-09-17-27-somebody.mp3
在此先感謝..
$file_types=array();
$file_types['mp3'] ='audio/mpeg';
$file_types['mpeg'] ='video/mpeg';
$file_types['mpg'] ='video/mpeg';
$file_types['pdf'] ='application/pdf';
$file_types['pps'] ='application/vnd.ms-powerpoint';
$file_types['ppt'] ='application/vnd.ms-powerpoint';
$file_types['ps'] ='application/postscript';
$file = 'you.mp3';
download($file,$file_types);
function download($file_name,$file_types){
$file = $file_name;
$ext = end(explode('.',$file_name));
if($ext && array_key_exists($ext,$file_types)){
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
}
else {
die("this is not a downloadable file");
}
}
?>
<a href="force_download.php?file=ok.txt"> download ok.txt</a>
因爲你的瀏覽器有mediaplayer擴展,它緩衝播放器識別的媒體文件。但是,如果您刪除擴展名或將擴展名更改爲其他內容,它會要求您下載,因爲該擴展名在瀏覽器中無法被mediaplayer擴展程序識別出來 – WatsMyName
您是否可以粘貼示例代碼?你是否試圖在PHP中打開一個文件,然後將其輸出到瀏覽器? – chovy
你能給一些代碼來理解嗎? – Ravi