Php is a simple method for clicking to download files on the current page,
Php controller code
public function downFile($path = ''){ if(!$path) header("Location: /"); download($path); }
Download file download function code
Function download ($ file_url, $ new_name = '') {if (! Isset ($ file_url) | trim ($ file_url) = '') {echo '000000';} if (! File_exists ($ file_url) {// check whether the file contains echo '000000';} $ 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 = fopen ($ file_url, 'R'); // open the file // enter the file tag header ("Content-type: application/octet-stream "); header (" Accept-Ranges: bytes "); header (" Accept-Length :". filesize ($ file_url); header ("Content-Disposition: attachment; filename = ". $ file_name); // echo fread ($ file_type, filesize ($ file_url); fclose ($ file_type );}
Html code
<Iframe id = "iframe" src = "" style = "display: none;"> </iframe> $ (function () {$ ('. downLoad '). click (function () {var path = $ (this ). attr ('path'); $ ('# iframe '). attr ('src', "php file path? Path = "+ path );})})
Put the above Code in your program for execution.
The above is all the simple methods provided by the editor for php to download files on the current page. I hope it will be helpful to you and support more help ~