我有这段代码,但它不断下载dashboard.php
而不是../config.php
<?php
$filename = "../config.php";
function forceDownLoad($filename){
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($filename).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
@readfile($filename);
exit(0);
}
forceDownLoad();
?>
为什么要下载dashboard.php
?我告诉他下载config.php
并继续下载dashboard.php
!!
答案 0 :(得分:2)
您的功能需要参数$filename
。您运行该函数时不会为其提供所需的参数(forceDownload();
),这会使您的函数$fileName
中出现NULL
。因此,它只是抓住你的网站的根并下载它。如果你有PHP错误,你会看到函数调用中缺少参数的通知。
请改为尝试:
forceDownload($fileName);