Php 如何弹出下载提示?

Php 如何弹出下载提示?,php,Php,我用它把内容放到一个文件里 file_put_contents('abc.txt', $text); 我需要有一个弹出窗口供用户在此之后保存/下载文件 我将如何做到这一点上的手册有一个完整的示例。使用内容处置标题: header('Content-Disposition: attachment; filename="abc.txt"'); readfile('abc.txt'); 同时确保发送适当的内容类型标题。您必须传递正确的标题: header("Content-disposition

我用它把内容放到一个文件里

file_put_contents('abc.txt', $text); 
我需要有一个弹出窗口供用户在此之后保存/下载文件
我将如何做到这一点

上的手册有一个完整的示例。

使用内容处置标题:

header('Content-Disposition: attachment; filename="abc.txt"');
readfile('abc.txt');

同时确保发送适当的内容类型标题。

您必须传递正确的标题:

header("Content-disposition: Atachment");

这将为用户提供下载提示:

<?php                                                                
header('Content-type: text/plain');                             

// What file will be named after downloading                                  
header('Content-Disposition: attachment; filename="abc.txt"');

// File to download                                
readfile('abc.txt');                                            
?>