PHP _php tutorial for downloading text files via headers

Source: Internet
Author: User
Tags readfile
The so-called implementation of the text file download means that when we click on a text file link is not open this file, but rather pop up a download dialog box let us download, this is the main topic discussed today. PHP Help document about PHP through the header trigger download of the instructions is relatively simple, and online about this aspect of the poor, there are many articles can not achieve the desired effect. Today I also talk about this topic, if you feel better than some articles on the Internet, then I am very satisfied. 6}g>o%p
If, from an accurate point of view, the PHP document is the most accurate, because it is a concise list of the implementation of the text class file to trigger the download required three statements, in the case of PDF is: g<
We ' ll be outputting a PDF Lh?cuj Qh
Header (' content-type:application/pdf '); I[XR. P
It'll be called downloaded.pdf rwf{=pk '
Header (' content-disposition:attachment; filename= ' downloaded.pdf '); Hoaw:* z{>
The PDF source is in Original.pdf j4qsc\1
ReadFile (' original.pdf '); 0pc*r4r@
<|
These three sentences are correct, but in the process of real use is very easy to have some unpredictable problems, if you are a very careful person, you can easily avoid these problems. And I am not, so I have encountered such a problem, here is my question to briefly say.1xraa7
For the first sentence, there should be nothing to say, is necessary, just change the type of document, for example, to download TXT file, then change to the header (' Content-type:application/txt '), and the second sentence does not say anything, is for your download document name, If it is a TXT file, it can be changed to the header (' content-disposition:attachment; filename= ' Downloaded.txt '); the third sentence is more problematic, ReadFile This function means to read a file and then output, where the path of the file 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. I am here to lack of careful observation, a look at the following is not immediately to check the code, and did not find that the above text is what I need to find this part of the content, you may soon think of how to solve the problem, that is, to close the text content of the page submitted to the output.i-z7 i;i
. Fro|}}
wr#r? DhI
Here, our problem is solved, so that the text file link will be clicked to trigger the Download dialog box effect.

http://www.bkjia.com/PHPjc/364127.html www.bkjia.com true http://www.bkjia.com/PHPjc/364127.html techarticle the so-called implementation of the text file download means that when we click on a text file link is not open this file, but pop up a download dialog box let us download, this is the present ...

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