Asim Zaidi
Asim Zaidi

Reputation: 28344

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

Upvotes: 3

Views: 6125

Answers (4)

Banjer
Banjer

Reputation: 8320

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

Upvotes: 10

Ikke
Ikke

Reputation: 101251

You have to pass the right headers:

header("Content-disposition: Atachment");

Upvotes: 0

netcoder
netcoder

Reputation: 67745

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.

Upvotes: 0

Pekka
Pekka

Reputation: 449783

The manual on fpassthru() has a complete example.

Upvotes: 2

Related Questions