已掉线,重新登录

首页 > 绿虎论坛 > 历史版块 > 编程 > PHP > 教程

标题: 实现php文件安全下载!

作者: @Ta

时间: 2013-12-21

点击: 2395

public function downloads($name){
$name_tmp = explode("_",$name);
$type = $name_tmp[0];
$file_time = explode(".",$name_tmp[3]);
$file_time = $file_time[0];
$file_date = date("Y/md",$file_time);
$file_dir = SITE_PATH."/data/uploads/$type/$file_date/";
if (!file_exists($file_dir.$name)){
header("Content-type: text/html; charset=utf-8");
echo "File not found!";
exit;
} else {
$file = fopen($file_dir.$name,"r");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($file_dir . $name));
Header("Content-Disposition: attachment; filename=".$name);
echo fread($file, filesize($file_dir.$name));
fclose($file);
}
}

[隐藏样式|查看源码]


『回复列表(2|隐藏机器人聊天)』

1. 不懂
(/@Ta/2013-12-21 13:37//)

2. @onlyone,亲,要传给$name 什么值呢
(/@Ta/2013-12-21 15:48//)

回复需要登录

9月11日 06:48 星期四

本站由hu60wap6驱动

备案号: 京ICP备18041936号-1