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

时间:2017-03-22 13:35:39

标签: php html download

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

代码:

createfile($secretkey, $botkey);
downloadfile($secretkey);
echo "<h1>Thank you for buying EX-7!</h1></br>";

功能createfile

$myfile = fopen($secretkey. ".txt", "w");
$txt = "Thank you for buying EX-7! We have whitelisted you for EX-7, Congratulations!";
fwrite($myfile, $txt);
fclose($myfile);

功能下载文件:

$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>

0 个答案:

没有答案