PHP强制下载头失败

问题描述 投票:0回答:1

我有一个问题,下面的代码无法正常工作,我也不明白为什么。

代码:

        $fileName = basename($_POST["filename"].".txt");
        $filePath = $fileName;
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=$fileName");
        header("Content-Type: text/plane");
        header("Content-Transfer-Encoding: binary");
        // Read the file
        readfile($filePath);
        exit;

输出:

<form method="post">
<input type="text" name="swrite" id="input1" placeholder="Text">
<input type="text" name="filename" id="input2" placeholder = "filename">
<button type="submit" onclick="localset()">submit</button>
</form>

Lorem Ipsum

The form is out of the .php file and I really don't know how to fix this.
php text download header
1个回答
-1
投票

您的代码对我来说很好。文件中其他地方是否还有其他标头?

© www.soinside.com 2019 - 2024. All rights reserved.