PHP force download file (click TXT file, save name after save).
since now browsers can recognize the format of the document format as TXT, so if only a text link is made to the txt document, it may just open a new window to display the content of the txt file, and it can't be implemented. Click on the purpose of downloading. We have to do something else.
, of course, the solution of this problem can also be that you rename your TXT file to a file that the browser does not know, such as rar, and then click on the browser, and the browser will have to let the user download it.
this file is the purpose of clicking downloads by setting the format of the header to set the document, and the files passed on the previous page can be downloaded.
[code].lt;? Php
$filename =.Quot; /somepath/.quot;.$_GET.#91;'file'.#93;..quot;.Txt.quot; />readfile ($filename);
?.gt; [/code]
First: set the value of Content-Type to be application/force-download, Download
second header functions to set the file to download, note that this is the file name that does not contain the path, so filter out the path name. The value of this filename in the future is the file name.
/>
readfile, and the file stream is output to the browser, thus the download of the txt file is realized, and the other types are similar.