PHP File Download Example

Source: Internet
Author: User

<?php Header ("Content-type:text/html;charset=utf-8"); $file _name= "Cookie.jpg"; $file _name= "3D.exe"; To solve the problem that cannot be displayed in Chinese $file _name=iconv ("Utf-8", "gb2312", $file _name); $file _sub_path=$_server[' Document_root ']. " /"; echo "<br/>file_sub_path:". $file _sub_path. " <br/> "; $file _path= $file _sub_path. $file _name; echo "<br/>filepath:". $file _path. " <br/> ";//first to determine whether a given file exists or not (!file_exists ($file _path)) {echo" does not have the file "; return;} $fp =fopen ($file _path," R "); $file _size=filesize ($file _path); The header ("Content-type:application/octet-stream") to be used to download the file; Header ("Accept-ranges:bytes"); Header ("Accept-length:". $file _size); Header ("content-disposition:attachment; Filename= ". $file _name); $buffer = 1024; $file _count=0; Return data to the browser while (!feof ($fp) && $file _count< $file _size) {$file _con=fread ($fp, $buffer); $file _count+=$ Buffer echo $file _con; } fclose ($fp);. 

PHP File Download Example

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.