Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除php脚本中的include文件_Php_Html - Fatal编程技术网

删除php脚本中的include文件

删除php脚本中的include文件,php,html,Php,Html,我有一个php文件来处理网站中的文件下载。它正在发挥应有的作用 if($_GET['type'] == "pdf") { $dir = __DIR__ . "/../src/files/pdf/" . $_GET['name']; if(file_exists($dir)) { header('Content-Description: File Transfer'); header('Content-Type: application/pdf');

我有一个php文件来处理网站中的文件下载。它正在发挥应有的作用

if($_GET['type'] == "pdf") {
    $dir = __DIR__ . "/../src/files/pdf/" . $_GET['name'];
    if(file_exists($dir)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/pdf');
        header('Content-Disposition: attachment; filename='.basename($dir));
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($dir));
        readfile($dir);
        exit;
    } else {
        $_SESSION['err'] = "No file found";
        header("location: index.php");
        exit;
    }
}
现在我想计算一个文件被下载的次数。因此,我在另一个php文件中的类中有一个方法。当我需要使用它的一些方法时,我通常包括这个php文件并创建这个类的一个实例。问题是,如果我在file-handler.php中包含该文件,则头将不同,下载时该文件将被损坏。
那么,如何在文件处理程序中使用此文件的方法而不影响头?

如果在输出下载头之前在file-hander.php文件的顶部包含counting file before,则下载头将替换之前输出的任何头

另外。您的计数文件不能输出任何内容,因为客户端期望您下载的文件,而不是其他内容


我百分之百同意@rjdown,你的代码会产生巨大的潜在安全问题。我不会把它放在连接到不可信网络(如互联网)的服务器上。如果您希望帮助确保安全,请提出这个问题。

您的随附文件中到底有什么内容?“标题将不同”是什么意思?请改用名称空间。如果包含一个新的php文件会改变您的
标题
发送,则所包含的文件有很大问题。这是非常可怕的代码。我几乎可以从您的服务器下载任何文件,假设PHP可以访问it@rjdown我使用这个建议进行了一些验证。