Php implements the code for clicking to download the TXT document in the browser
- /**
- * Click to download the txt document.
- * Edit bbs.it-home.org
- */
- $ Filename = '/path/'.w._getw.'file'{.'.txt'; // file path
- Header ("Content-Type: application/force-download ");
- Header ("Content-Disposition: attachment; filename =". basename ($ filename ));
- Readfile ($ filename );
- ?>
Note: the first header function sets the Content-Type value to application/force-download; the second header function sets the file to be downloaded. Note that the filename here is a file name that does not contain a path. The value of filename will be the file name in the pop-up dialog box after you click Download. if there is a path, the file name in the pop-up dialog box is unknown; finally, the readfile function is used to output the file stream to the browser, so as to download the txt file. |