What happens if you let the browser access a TXT file? For example, to visit Localhost/test/test.txt, the browser will direct the contents of the TXT file
displayed directly on the browser instead of downloading it.
However, not all files will be read directly on the browser, such as. zip,. doc and so on will be downloaded directly, like. jpg,.png,.txt files will be read directly. Sometimes, txt and other files are relatively large, we do not want the browser directly read out, the server pressure is also relatively large.
At this point, you can specify the header information:
$file = fopen ($url, "R"); Open File Urlheader ("Content-type:application/octet-stream"); Specifies that the MIME type is an octal file stream header ("Accept-ranges:bytes"); Header ("Accept-length:". FileSize ($url)); Header (" Content-disposition:attachment; Filename= $name "); $name is the name of the file, generally in the last echo fread ($file, FileSize ($url)) of the. fclose ($file);
At this point, the files specified by the file can be downloaded instead of being read directly.
The above introduces PHP to allow the browser to download TXT and other types of files, including download txt, browser download content, I hope that the PHP tutorial interested in a friend helpful.