thinkphp 使用http扩展类 下载png等图片格式文件正常,但是下载doc,zip等文件时没有后缀
上传正常,下载png也是正常,就是doc,zip这类的文件下载下来,没有后缀打不开。怎么个情况呢?...
上传正常,下载png也是正常,就是doc,zip这类的文件下载下来,没有后缀打不开。怎么个情况呢?
展开
展开全部
header 制定的下载类型不对,
$extension=pathinfo($file, PATHINFO_EXTENSION);
switch ($extension){
case "jpg":
case "jpeg": $ctype="image/jpeg"; break;
case "pdf": $ctype="application/pdf"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "doc": $ctype="application/msword"; break;
case "zip": $ctype="application/zip";break;
case "rar": $ctype="application/rar"; break;
case "mp3": $ctype="audio/mpeg3"; break;
case "avi": $ctype="video/avi"; break;
case "doc": $ctype="application/msword";break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "wav": $ctype="audio/wav"; break;
case "htm": $ctype="text/html"; break;
case "txt": $ctype="text/plain"; break;
case "flv": $ctype="flv-application/octet-stream"; break;
case "mp4": $ctype="video/mp4"; break;
default: $ctype="application/force-download"; //$ctype="application/octet-stream";
}
header("Content-type: ". $ctype);
$extension=pathinfo($file, PATHINFO_EXTENSION);
switch ($extension){
case "jpg":
case "jpeg": $ctype="image/jpeg"; break;
case "pdf": $ctype="application/pdf"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "doc": $ctype="application/msword"; break;
case "zip": $ctype="application/zip";break;
case "rar": $ctype="application/rar"; break;
case "mp3": $ctype="audio/mpeg3"; break;
case "avi": $ctype="video/avi"; break;
case "doc": $ctype="application/msword";break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "wav": $ctype="audio/wav"; break;
case "htm": $ctype="text/html"; break;
case "txt": $ctype="text/plain"; break;
case "flv": $ctype="flv-application/octet-stream"; break;
case "mp4": $ctype="video/mp4"; break;
default: $ctype="application/force-download"; //$ctype="application/octet-stream";
}
header("Content-type: ". $ctype);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询