开发者

How do I pop up a download prompt?

I am using this to put the contents to a file

file_put_contents('abc.txt', $text); 

I need to 开发者_开发知识库have a pop up for the user after this to save/download the file how would I do that


This will give the user a download prompt:

<?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');                                            
?>  


The manual on fpassthru() has a complete example.


Use the Content-Disposition header:

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

Be sure to send the appropriate Content-Type header as well.


You have to pass the right headers:

header("Content-disposition: Atachment");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜