<?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