PHP header function Implementation of text file download method

Source: Internet
Author: User
  1. Header (' content-type:application/pdf ');
  2. Header (' content-disposition:attachment; filename= ' downloaded.pdf ');
  3. ReadFile (' original.pdf ');
  4. ?>
Copy Code

Description of the above code: the first sentence, just change the type of the document, for example, to download the TXT file, then the header (' Content-type:application/txt '), the second sentence is for your download document name, if it is a TXT file , you can change the header (' content-disposition:attachment; filename= ' Downloaded.txt '); the third sentence, ReadFile This function means to read a file and then output, The path of the file here needs to be the real file path, if it is a original.txt file under the Downloads folder, you can write ReadFile (' Downloads/original.txt '), and if the submitted page will output characters such as text , then the downloaded file will be a mixed file of the original file original.txt and the text of the submitted page output.

With the above understanding, the implementation of the TXT file download, you can also easily solve.

In addition, for the convenience of understanding, it is recommended to read the following: PHP header Content-type Type summarizes this article, summarizes the very comprehensive PHP header content type.

  • 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.