PHP force download file (click TXT file, save name after save).

time:13-04-09 forum:PHP tools and code
  Reloaded from http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2010/0323/4192.html

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.

prev:A brief introduction to the usage of the... next:Ji'nan circus troupe Mongolia performanc...
post comment
Notice



approved   "Your advice really can't help me." ...   A rare picture of the old Ji'nan! Th...   The deep mountain women's back husba...   Sichuan Leshan 84 year old Lao Tai a...   Loss of breast and cancer coexistenc...
rand   PHP string intercept function substr...   Snoopy is used to imitate the functi...   PHP class of Snoopy powerful browser...   Advantages and disadvantages of cURL...   PHP cURL to achieve simulation login...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com