简体   繁体   中英

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

fpassthru()手册有一个完整的例子。

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.

你必须传递正确的标题:

header("Content-disposition: Atachment");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM