PHP code to implement the download function, download files from the server to Local:
Public Function downloadtemplateaction ()
{
define (' z_web_root ', ' http://' $_server[' server_name ');--------host
$file _name = "template.xlsx";
$file _dir = z_web_root. " /site/public/template/"; The directory where the---------file resides
$file = @ fopen ($file _dir. $file _name, "R");
if (! $file) {
echo "File does not exist.";
} else {
Header ("Content-type:application/octet-stream");
Header ("content-disposition:attachment; Filename= ". $file _name);
while (!feof ($file)) {
Echo fread ($file, 50000);
}
Fclose ($file);
}
}
Detailed Explanation:
the role of the Header ("Content-type:application/octet-stream"): This code browser allows you to know the file format returned by the server.
Header ("content-disposition:attachment; Filename= ". $file _name): tells the browser the name of the file returned.
Fclose ($file) can output the last remaining data in the buffer to a disk file, releasing the file pointer and the associated buffer.
The above describes the PHP implementation of the download file features, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.