Code in the PHP controller
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 ';
}
if (!file_exists ($file _url)) {//Check the file for the presence of
echo ' 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=fopen ($file _url, ' R '); Open file
//input 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);
Output file content
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, respectively, into your program to execute on it.
The above is a small series for everyone to bring PHP to achieve the current page click to download the simple method of the full content of the file, I hope to help you, a lot of support cloud Habitat Community ~