Yesterday look at Ecshop source, met a little did not learn just-how to use PHP implementation to download XLS file. According to its source code, I have implemented a bit, successfully achieved this effect.
Source:
Copy CodeThe code is as follows:
/*
* @Description: Download xls table
*
*
*/
function Downloadxls ($filename = ") {
$filename =!empty ($filename)? $filename: Die (' nothing ');
The function of the header is to create a new downloaded Test.xls
Header ("Content-type:application/vnd.ms-excel; Charset=utf8 ");
Header ("content-disposition:attachment; Filename= $filename ");
This needs to be output output directly to the Test.xls file.
Echo ' This is the test! ';
Exit
}
$fileName = ' Test.xls ';
Downloadxls ($fileName);
?>
Effect:
Note: If the output is in Chinese information, you should pay attention to the character encoding format conversion!
But what if I want to download the XLS file saved in the server?
After reviewing the PHP manual: find it easy to implement this function, using a ReadFile function. The code is as follows:
Copy CodeThe code is as follows:
/*
* @Description: Download xls table
*
*
*/
function Downloadxls ($filename = ") {
$filename =!empty ($filename)? $filename: Die (' nothing ');
The function of the header is to create a new downloaded Test.xls
Header ("Content-type:application/vnd.ms-excel; Charset=utf8 ");
Header ("content-disposition:attachment; Filename= $filename ");
Here is the file that needs to be exported
ReadFile ($filename);
}
$fileName = ' Test.xls ';
Downloadxls ($fileName);
?>
Effect:
Another extension: What if I want to download a txt file, a PDF file?
The way to do this is to modify the contents of the Content-type in the header output!
There is not much place, please the Great God pointed out!
http://www.bkjia.com/PHPjc/756338.html www.bkjia.com true http://www.bkjia.com/PHPjc/756338.html techarticle yesterday look at Ecshop source, met a little did not learn just-how to use PHP implementation to download XLS file. According to its source code, I realized a bit, successfully realized this ...