PHP let browser download txt and other types of files UC Browser import txt browser open txt speed browser Rule tx

Source: Internet
Author: User
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.