online, etc., asked if you know, PHP when downloading CSV file in the file why HTML sourceXLS file is normal
Reply to discussion (solution)
Based on your bad description, I can only give a bad answer?? There's something wrong with your code.
I put PHP generated CSV file on the page, click to download, open the download CSV Open after the content of the last HTML code to understand it!
When you build it, you have it.
To see your code
if ($opt = = ") {if (!in_array ($userid, $okuser)) {echo" You do not have permission to browse this page "; Exit } else {$web _folder = "/tj/"; $log _folder = "/tj/"; } $logFile = Array (), if (Is_dir ($log _folder)) {if ($dh = Opendir ($log _folder)) {while ($file = Readdir ($DH))! = False) {if ($file! = "." && $file! = "...") {$logFile [$file] = $file. "&ver=". Mt_rand (); }}}}arsort ($logFile), $smarty->assign ("LogFile", $logFile), $smarty->assign ("Web_folder", $w Eb_folder);} ElseIf ($opt = = ' Download ') {if (!in_array ($userid, $okuser)) {echo "You do not have permission to browse this page"; Exit } $filename = $cgi->filename;header ("Content-type:text/csv"); Header ("Content-type:text/xls"); Header (" Content-disposition:attachment;filename= ". $filename); ReadFile ("/tj/". $filename);} else {echo "You do not have permission to browse this page"; Exit;}This is the PHP code
{if $opt = = '} {include file= "menus.htm"} Statistics:
| Download link |
| {foreach from= $logfile key=k item=v}{$k}{/foreach} |
PHP generated a.csv file can certainly be right, but through a page download, a page of the HTML source also output to the CSV file
More depressed!
Visually your last table is not closed.
I pasted the problem closed, it seems that the problem is seldom met Ah!
Header ("Content-type:text/csv");
Header ("Content-type:text/xls");
How to send two Content-type head
Yes, because I'm going to download something with the XLS format also has CSV format
I checked, found the problem, the problem is
readfile ("/tj/". $filename);
{include file= "foot.htm"}{/if}{if $opt = = ' Download '}{/if} This is HTML code
This sentence, read the document to a die ();
Suppress page output, otherwise, the exported Excel will appear the HTML source of the request page; Workaround: Add a die () or exit after the redfilie sentence.