php中(文件下载)

来源:互联网 发布:js身份证号码格式验证 编辑:程序博客网 时间:2024/05/18 22:16

普通下载

header('content-type:text/html;charset=utf-8');
//接收文件路径
$path = $_GET['path'];
$filename = substr($path,strrpos($path,"/")+1);
//文件类型
header('Content-type: image/pjpeg');
//激活一个下载的窗口   (文件名)
header("Content-Disposition: attachment; filename=$filename");
//读文件
readfile($path);



TP下载

//获取要下载的文件id
$sid=$_GET['sid'];
//查找文件路径
$obj=M('song');
$spath=$obj->where("s_id=$sid")->find();
$path = "./Public/".$spath['s_path'];
$filename = substr($path,strrpos($path,"/")+1);
//文件类型
header('Content-type: mp3/mp4');
//激活一个下载的窗口   (文件名)
header("Content-Disposition: attachment; filename=$filename");
//读文件
readfile($path);
0 0
原创粉丝点击