Since the current browser can already recognize the TXT document format, if only to make a text link to the TXT document, click to open a new window to display the contents of the TXT file, and can not achieve the purpose of click to download. Of course, the solution to this problem can also be renamed TXT file to the browser does not know the file (such as RAR), so that the browser does not recognize the RAR type files, can only let users download. Another way is to use the code to format the document through the header to achieve the purpose of click to download.
The PHP code is as follows:
===========================================================
$filename = '/path/'. $_get[' file '. '. TXT '; File path
Header ("Content-type:application/force-download");
Header ("content-disposition:attachment; Filename= ". basename ($filename));
ReadFile ($filename);
===========================================================
Brief Description:
The first header function sets the value of Content-type to Application/force-download;
The second header function sets the file to be downloaded. Note that the filename here does not include the path of the file name, the value of filename will be clicked after the download pop-up dialog box file name, if the path, pop-up dialog box filename is unknown;
Finally through the ReadFile function, the file stream output to the browser, so that the implementation of the TXT file download.
http://www.bkjia.com/PHPjc/327087.html www.bkjia.com true http://www.bkjia.com/PHPjc/327087.html techarticle since the current browser can already recognize the TXT document format, if only to make a text link to the TXT document, click on just open a new window to display the contents of the TXT file, and can not ...