下载

原创
2012/06/30 14:29
阅读数 20
<?php

$path = '1.rar';

$extension = getFileExt($f);

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;  
default: $ctype="application/force-download";
}

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-type: ". $ctype);
header("Content-Transfer-Encoding: binary");
header("Content-Length: ". filesize($path));
header('Content-Disposition: attachment; filename="100.jpg" ;');

readfile(   $path  ); // 这个 path 是真是路劲,类似:c:\1.jpg

function getFileExt($file_name){  
$extend = explode("." , $file_name);  
$type = $extend[count($extend)-1];
return strtolower($type);  
}  
?>
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部