Php 从服务器下载文件时出现问题

Php 从服务器下载文件时出现问题,php,html,download,Php,Html,Download,当尝试从我的服务器下载.txt文件时,它正在下载当前显示的页面。我希望它回显页面上的文本,然后下载后,一个txt文件上传到服务器上 代码: 函数下载文件: $filename = $secretkey. '.txt'; header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Length: ". filesize("

当尝试从我的服务器下载
.txt
文件时,它正在下载当前显示的页面。我希望它回显页面上的文本,然后下载后,一个txt文件上传到服务器上

代码:

函数下载文件:

$filename = $secretkey. '.txt';
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-Length: ". filesize("$filename").";");
        header("Content-Disposition: attachment; filename=$filename");
        header("Content-Type: application/octet-stream; "); 
        header("Content-Transfer-Encoding: binary");

        readfile($filename);
它正在下载文件,但文件的文本为:

<html>
<head>
    <title> Thank you for purchasing! </title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
    <div class="middlediv">

    <div class="text">
        <h1>Thank you for buying EX-7!</h1>

感谢您的购买!
感谢您购买EX-7!

你怎么说没有解决。它们都已解决?“已解决”=很抱歉,我不知道我必须接受解决方案。您刚刚在许多人的脸上露出微笑:-)干杯您给出的代码没有任何问题。代码运行良好
$filename = $secretkey. '.txt';
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-Length: ". filesize("$filename").";");
        header("Content-Disposition: attachment; filename=$filename");
        header("Content-Type: application/octet-stream; "); 
        header("Content-Transfer-Encoding: binary");

        readfile($filename);
<html>
<head>
    <title> Thank you for purchasing! </title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
    <div class="middlediv">

    <div class="text">
        <h1>Thank you for buying EX-7!</h1>