Web page provides file download function

Source: Internet
Author: User
Tags fread
HTML PHP

What is the difference between HTML implementation file download and PHP implementation?
How to let the user can only download the file through the link on the webpage, can't find it through the address?


Reply to discussion (solution)

Database to store the path of the download, click Query Database, find the download address.

But this is not very safe, the download address will eventually be exposed

Web links to a PHP, this PHP based on the address to read the file, and then segmented output

The first parameter, you can make the path more complex $file = fopen ($file _dir. $file _name, "R"); Open the file//input file tag header for download ("Content-type:application/octet-stream"); Header ("Accept-ranges:bytes"); Header ("Accept-length:". FileSize ($file _dir. $file _name)); Header ("content-disposition:attachment; Filename= ". $file _name);//output file contents//Echo fread ($file, FileSize ($file _dir. $file _name));//Output Fread ($file, FileSize ($file _dir. $ file_name)); fclose ($file); exit ();


Very easy to find code
  • 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.