我试图用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文件。 –