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");
精彩评论