Php 由服务器发送的Chrome双头文件

Php 由服务器发送的Chrome双头文件,php,google-chrome,header,download,force-download,Php,Google Chrome,Header,Download,Force Download,我使用php强制下载任何文件,这是我的代码 index.php <a href="download.php?file_name=example.png"><button class="details_button_T">Télécharger</button></a> $file= $_GET['file_name']; if (file_exists($file)) { header('Content-Description:

我使用php强制下载任何文件,这是我的代码


index.php

<a href="download.php?file_name=example.png"><button class="details_button_T">Télécharger</button></a>
$file= $_GET['file_name'];
if (file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit();
    }

该代码只在所有浏览器中工作chrome显示一个错误:服务器发送的双标题已解决这是一个小错误

header('Content-Disposition: attachment; filename="'.basename($file).'"');

确保属性filename=“NAME.xxx”必须具有双字节密码非常重要。在de header内部。

F12并查看网络选项卡,它将向您显示标题,以便您可以看到哪个标题是重复的。从那里开始。我猜是缓冲区功能导致了问题,或者至少是造成问题的原因。你允许恶意用户查看服务器上他们知道路径的任何文件<代码>http://example.com/download.php?file_name=/etc/passwd有人吗?解决问题后,我会关注安全性。在网络部分的“f12开发工具>网络>选择请求”(可能是唯一一个请求,我想它会显示为红色)>选择“标题”选项卡(首先在右侧框中>响应标题)