PHP function code to complete the download file via function
function Download ($url, $filename) {//Get file size, prevent more than 2G of files, read with sprintf = sprintf ("%u", FileSize ($url));
if (! $filesize) {return; Header ("content-type:application/octet-stream\n");
Application/octet-stream header ("Content-type:unknown/unknown;"); Header ("content-disposition:attachment; Filename=\ "". $filename.
"\"" );
Header (' content-transfer-encoding:binary ');
if ($range = getenv (' Http_range ')) {//when there is an offset, use a 206 breakpoint to renew the head $range = explode (' = ', $range);
$range = $range [1];
Header ("http/1.1 206 Partial Content"); Header ("Date:"). Gmdate ("D, D M Y h:i:s").
"GMT"); Header ("last-modified:"). Gmdate ("D, D M Y h:i:s", Filemtime ($url)).
"GMT");
Header ("Accept-ranges:bytes"); Header ("Content-length:").
($filesize-$range)); Header ("Content-range:bytes"). $range. ($filesize-1). "/" .
$filesize); Header ("Connection:close").
"\ n"); else {header ("Content-length:"). $filesize. "\ n");
$range = 0;
} loadfile ($url);
function LoadFile ($filename, $retbytes = True) {$buffer = '; $cnt = 0; $handle = fopen ($filename, ' RB ');
if ($handle = = False) {return false;
while (! feof ($handle)) {$buffer = Fread ($handle, 1024 * 1024);
Echo $buffer;
Ob_flush ();
Flush ();
if ($retbytes) {$cnt + + strlen ($buffer);
}} $status = Fclose ($handle);
if ($retbytes && $status) {return $cnt,//Return num. Bytes delivered like ReadFile () does. return $status;}
Enter 2 parameters to complete download Download ($url, $filename)
The above is a small set to introduce PHP download file Function example code of the relevant knowledge, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!