PHP downloads the function instance code of the file ,. Function instance code of the PHP file to be downloaded. the Function Code functiondownload ($ url, $ filename) {obtains the file size to prevent files larger than 2 GB, use spr PHP to download the function instance code of the file,
PHP code for downloading objects using functions
Function download ($ url, $ filename) {// Obtain the file size. to prevent files larger than 2 GB, use sprintf to read $ filesize = 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 the 206 resumable Upload header $ 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 two parameters to download ($ url, $ filename)
The above section describes the knowledge of function instance code for downloading PHP files. I hope it will be helpful to you. if you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!
Complete: use the function to download the PHP function code of the file. function download ($ url, $ filename) {// Obtain the file size to prevent files exceeding 2 GB. use spr...