How to use PHP to force file Download _php Tutorial

Source: Internet
Author: User
Tags readfile
PHP allows you to change the HTTP headers that you write so that you can force a file to be downloaded, typically, the browser will load the files in the same window. This is perfect for documents such as PDF files, document files, pictures, videos that you want your customers to download, rather than read online.
Here's how:

1, you want to download the file to your Web server to upload. For example
Huge_document.pdf
2. Edit the new php file-I recommend naming it as the same as the name of the file you downloaded, just to PHP extensions. For example:
huge_document.php
3. Open the PHP module:
<? Php
4, in the next line, set the HTTP header:
Header (' content-disposition:attachment; Filename=huge_document.pdf ');
5, and then set the MIME type of the file:
Header (' content-type:application/pdf ');
6, point to the file you want to download:
ReadFile (' huge_document.pdf ');
7, then close the PHP block and save the file:
> [/blockquote>
8, your PHP file should look like this:
Header (' content-disposition:attachment; Filename=huge_document.pdf ');
Header (' content-type:application/pdf ');
ReadFile (' huge_document.pdf ');
?>
9. Links to the download link to your php file. For example:
Download huge files (PDF)

http://www.bkjia.com/PHPjc/477926.html www.bkjia.com true http://www.bkjia.com/PHPjc/477926.html techarticle PHP allows you to change the HTTP headers that you write so that you can force a file to be downloaded, typically, the browser will load the files in the same window. This is the perfect document, such as ...

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