我試圖用php下載一些文件來隱藏文件路徑,但是一些文件類型總是被破壞。 像PDF和MP3文件類型很好。 像doc,ppt,jpg等文件類型總是下載破碎。用php下載jpg,doc,ppt文件已損壞
我使用這些MIME類型
if (file_exists($file_real)){
$extension = strtolower(substr(strrchr($file, "."), 1));
switch($extension){
case "ppt": $type = "application/vnd.ms-powerpoint"; break;
case "pdf": $type = "application/pdf"; break; //------ok
case "doc": $type = "application/msword"; break;
case "mp3": $type = "audio/mpeg"; break;//------ok
case "jpg": $type = "image/jpg"; break;
default: $type = "application/force-download"; break;
}
和這些頭
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public", false);
header("Content-Description: File Transfer");
header("Content-Type: " . $type);
header("Accept-Ranges: bytes");
header("Content-Disposition: attachment; filename=\"" . $header_file . "\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($file_real));
if ($stream = fopen($file_real, 'rb')){
while(!feof($stream) && connection_status() == 0){
set_time_limit(0);
print(fread($stream,1024*8));
flush();
}
fclose($stream);
}
你正在下載PPT/DOC或PPTX/DOCX? DocX內容類型是「application/vnd.openxmlformats-officedocument.wordprocessingml.document」,PPTX是「application/vnd.openxmlformats-officedocument.presentationml.presentation」 – AvkashChauhan
你打開和輸出文件的方式是什麼? – user2428118
使用word2003創建的Doc文件和使用powerpoint2003的powerpoint文件。 –