PHP implementation file Download simple example _php Tutorial

Source: Internet
Author: User
Tags ranges
This article mainly introduces the PHP implementation file Download Simple example, the need for friends can refer to the following

The code is as follows: Public function downloads ($name) {$name _tmp = explode ("_", $name); $type = $name _tmp[0]; $file _time = Explode (".", $ NAME_TMP[3]); $file _time = $file _time[0]; $file _date = Date ("Y/md", $file _time); $file _dir = Site_path. " /data/uploads/$type/$file _date/"; if (!file_exists ($file _dir. $name)) {header ("content-type:text/html; Charset=utf-8 "); echo "File not found!"; Exit } else {$file = fopen ($file _dir. $name, "R"); Header ("Content-type:application/octet-stream"); Header ("Accept-ranges:bytes"); Header ("Accept-length:". FileSize ($file _dir. $name)); Header ("content-disposition:attachment; Filename= ". $name); Echo fread ($file, FileSize ($file _dir. $name)); Fclose ($file);}} Example 2: Code implementation file Download general implementation download is called URL to download, but encountered IE can recognize open files can not be used in this way, such as downloading a picture, HTML page, etc., then need to be programmed to implement, the following PHP code can be resolved: The code is as follows:

http://www.bkjia.com/PHPjc/739908.html www.bkjia.com true http://www.bkjia.com/PHPjc/739908.html techarticle This article mainly introduces the PHP implementation file Download Simple example, the need for friends can refer to the following code: Public Function Downloads ($name) {$name _tmp = explode (_, $name); $type = $ Name ...

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