This site has previously shared a file download function, the specific article connection address is as follows:
PHP File Download function (code)
Recently a customer reflects that all the pictures on their website can not download, download the images are broken, direct results can not open, the author tested the next discovery does have this problem, carefully read the source code, found the root cause of the problem in fread this function, The second parameter of the Fread function is to set the maximum number of bytes to read, and the test finds that the maximum number of bytes that can be read by the Fread function is limited, only 8,192 bytes, or 8KB, for files that exceed this size, and if the file is to be fully read, it needs to be looped until the end of the file. Comprehensive above to make some corrections, the following code is after the rest of the code, after testing the problem solved.
function Download ($file _url, $new _name= ") {if (!isset ($file _url) | | Trim ($file _url) = = ") {return ' 500 ';} if (!file_exists ($file _url)) {//Check the file for the existence of return ' 404 ';} $file _name=basename ($file _url), $file _type=explode ('. ', $file _url); $file _type= $file _type[count ($file _type) -1];$ File_name=trim ($new _name== ")? $file _name:urlencode ($new _name). $file _type;//input File label phpernoteheader ("Content-type:application/octet-stream"); Header ("Accept-ranges:bytes"); Header ("Accept-length:". FileSize ($file _url)); header ("Content-disposition:attachment; Filename= ". $file _name);//Output file contents @readfile ($file _type);}
Articles you may be interested in
- Upload and download files using SECURECRT (with SZ and RZ commands)
- Hosts file location and how to open Hosts file
- PHP parsing file header information to determine the type of upload file
- PHP Empty (delete) the file under the specified directory, do not delete the Directory folder method
- PHP uses Curl Functions to crawl Web pages and download files in multiple threads
- PHP File Download function (code)
- PHP limit file Download speed function
- Move the mouse to text on the floating Layer hint effect (compatible with IE, Firefox and other browsers)
http://www.bkjia.com/PHPjc/764096.html www.bkjia.com true http://www.bkjia.com/PHPjc/764096.html techarticle This site has previously shared a file download function, the specific article connection address is as follows: Php file download function (code) Recently a customer reflects all the pictures on their website can not download, ...