There is an issue with this output. When the user clicks the button, it should spit out an excel sheet. However, for some users, it spits out an HTML page. I have a feeling it has something to do with other users having IE7 instead of IE10. However, this function should work for both.
Please help.
Let me know if you can spot the error:
$time = time();
$illegals = array('!', '*', "'", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]", "\"");
if(isset($_GET['ns_title'])) {$filename = str_replace($illegals,"",urldecode($_GET['ns_title'])).".xls"; } else { $filename = "myreport$time.xls"; }
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Expires: 0");
print "$headers
$data";
You're specifying two types of Content-type
's - stick with application/octet-stream
or supply the actual Excel content type (See Bastien's answer).
Secondly, what's $headers
and $data
? We'll assume you're using those thinking they set the headers - but header()
already does this.
You could use readfile($filename)
if it's a real file, or simply echo content that you want to start the browser download.
try this official MIME type application/vnd.ms-excel