logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: excel file opens as a web page instead of downloading using
Author
kpeter32



Joined: 06 Mar 2018
Posts: 5
Location: US

PostPosted: Wed 07 Mar '18 22:18    Post subject: excel file opens as a web page instead of downloading using Reply with quote

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: 7288
Location: Germany, Next to Hamburg

PostPosted: Thu 08 Mar '18 10:39    Post subject: Reply with quote

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

PostPosted: Thu 08 Mar '18 16:36    Post subject: data still opening in web browser Reply with quote

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: 7288
Location: Germany, Next to Hamburg

PostPosted: Fri 16 Mar '18 0:29    Post subject: Reply with quote

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

PostPosted: Tue 20 Mar '18 15:19    Post subject: developer tools Reply with quote

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: 7288
Location: Germany, Next to Hamburg

PostPosted: Tue 20 Mar '18 15:40    Post subject: Reply with quote

The excel file has the header Content type html? In both cases?
Back to top
kpeter32



Joined: 06 Mar 2018
Posts: 5
Location: US

PostPosted: Tue 20 Mar '18 21:55    Post subject: excel file opens as webpage instead of dwonloading Reply with quote

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

PostPosted: Tue 20 Mar '18 21:57    Post subject: additional code Reply with quote

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>
&nbsp
<a class="bodyLink" href='disputedreports.php?download="true"'>Download Excel Sheet</a>
<?php
Back to top


Reply to topic   Topic: excel file opens as a web page instead of downloading using View previous topic :: View next topic
Post new topic   Forum Index -> Apache