Author |
|
kpeter32
Joined: 06 Mar 2018 Posts: 5 Location: US
|
Posted: Wed 07 Mar '18 22:18 Post subject: excel file opens as a web page instead of downloading using |
|
|
I have a Windows 2012 r2 server that is running Apache 2.2.14 as the web service. On this server I am running a PHP file to display a web page that allows the end user to download an excel file. This file use to run on a 2003 windows server using Apache 2.0. Since I have transferred the files over to the 2012 R2 server the excel file is opening as a web page. The code has not changed so i am not sure why it is not giving the end user the option to download or save. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Thu 08 Mar '18 10:39 Post subject: |
|
|
You can add some headers to the download in php ( if you are using that)
Code: |
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
|
or you can set the content type in apache mime types. |
|
Back to top |
|
kpeter32
Joined: 06 Mar 2018 Posts: 5 Location: US
|
Posted: Thu 08 Mar '18 16:36 Post subject: data still opening in web browser |
|
|
I have checked both of these settings and they are set correctly and the php works great on a windows 2003 server running apache 2.0.55 but it just opens in a web page on the 2012 R2 server running apache 2.2.14. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Fri 16 Mar '18 0:29 Post subject: |
|
|
If you use Firefox or Chrome use the developer tools, use the network tab and report which headers are being send to the browser. |
|
Back to top |
|
kpeter32
Joined: 06 Mar 2018 Posts: 5 Location: US
|
Posted: Tue 20 Mar '18 15:19 Post subject: developer tools |
|
|
I have opened the developer tools on both firefox and chrome and the file is listed as a html but it works perfect on a windows 2003 server running apache 2.0 using the same code and apache 2.2 on a windows 2012 r2 server it opens in the browser. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 20 Mar '18 15:40 Post subject: |
|
|
The excel file has the header Content type html? In both cases? |
|
Back to top |
|
kpeter32
Joined: 06 Mar 2018 Posts: 5 Location: US
|
Posted: Tue 20 Mar '18 21:55 Post subject: excel file opens as webpage instead of dwonloading |
|
|
Here is what my code looks like
if (file_exists($filename))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($filename));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filename));
ob_clean();
flush();
readfile($filename);
} |
|
Back to top |
|
kpeter32
Joined: 06 Mar 2018 Posts: 5 Location: US
|
Posted: Tue 20 Mar '18 21:57 Post subject: additional code |
|
|
This is the code that is used to create the button that prompts the download
<td align="center" class="bodyMain" colspan="8">
<b>From:</b> (<?php echo $fromdate; ?>) <b>To:</b> (<?php echo $todate; ?>)<br />
<a class="bodyLink" href="javascript:launchPrint(<?php echo "'$fromdate','$todate','$show_unprinted'"; ?>)">Print this list</a>
 
<a class="bodyLink" href='disputedreports.php?download="true"'>Download Excel Sheet</a>
<?php |
|
Back to top |
|