PHP php 文件下载代码

malcolm · 2022-04-09 11:29:36 · 热度: 8

php 文件下载代码

<?php
 
$filename = $_GET['filename'];
 
// 修改这一行设置你的文件下载目录
$download_path = "ficheros/";
 
// 不能下载上一层目录的文件
if(eregi("\.\.", $filename)) die("抱歉,你不能下载该文件!");
$file = str_replace("..", "", $filename);
 
// 包含 .ht 的文件不能下载
if(eregi("\.ht.+", $filename)) die("抱歉,你不能下载该文件!");
 
// 创建文件下载路径
$file = "$download_path$file";
 
// 判断文件是否存在
if(!file_exists($file)) die("抱歉,文件不存在!");
 
//  文件类型,作为头部发送给浏览器
$type = filetype($file);
 
// 获取时间和日期
$today = date("F j, Y, g:i a");
$time = time();
 
// 发送文件头部
header("Content-type: $type");
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');
// 发送文件内容
set_time_limit(0);
readfile($file);
 
?>

猜你喜欢:
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册