How do I open a download hint?

I use this to put contents in a file

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

I need to open a popup for the user to save / load the file as I would do

+3
source share
4 answers

This will give the user a download request:

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

The manual fpassthru()provides a complete example.

+2
source

Use the Content-Disposition header:

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

Be sure to send the appropriate Content-Type header.

0
source

You must pass the correct headers:

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

Source: https://habr.com/ru/post/1773949/


All Articles