PHP implementation of File Direct output Download _php tutorial

Source: Internet
Author: User
You're going to laugh at me. "Download file" So simple is worth saying? Of course it's not as simple as you think. For example, you want customers to fill out a form, you can download a file, your first thought must be "Redirect" method, first check whether the form has been completed and complete, and then the URL refers to the file, so that customers can download, such as the author of the following code:


Check if the form is complete ...

if ($form _completed) {

Header ("Location:http://www.etoow.com/download/info_check.exe");

Exit

}

?>

Or in the following cases:

"Start download File"

The ID is used here to receive the number of the file to download, and then "Redirect" the way to connect to the actual URL.

If you want to do an e-commerce website on "online shopping", considering security issues, you do not want users to directly copy the URL to download the file, I suggest you use PHP directly read the actual file and then download the method to do. The procedure is as follows:


$file _name = "Info_check.exe";

$file _dir = "/public/www/download/";

if (!file_exists ($file _dir. $file _name)) {//check if file exists

echo "File not found";

Exit

} else {

$file = fopen ($file _dir. $file _name, "R"); Open File

Input File Label

Header ("Content-type:application/octet-stream");

Header ("Accept-ranges:bytes");

http://www.bkjia.com/PHPjc/630407.html www.bkjia.com true http://www.bkjia.com/PHPjc/630407.html techarticle you're going to laugh at me. Downloading a file is so simple and worth saying? Of course it's not as simple as you think. For example, you want the customer to fill out a form before they can download a file, your first ...

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