strange page refresh issue

Good day all:
I have a small script that will allow users to select a database table and extract the data into an excel file. This all works well, but the page acts relatively strange after the file has been downloaded.

What is happening is that after the file is retrieved, the page does not refresh, and in Firefox, if I select another file to extract, it will draw unformatted plain html as text to the screen.

It would appear as though the export to excel is creating the excel file and also the download header correctly, but it is not redrawing the form.html.php page(???).

I think that what I need is a way to force the download page to process, and then flush the header so that the form.html.php can fully reload (see the code index.php below and also the header details from the excel process). I did a test on the page to see if a control element is being reset changed after the file download process. I created a variable in the controller and in the form page, if the value is a 1, I display a message, otherwise I do not. Initially I set it to display the message (first load), then I processed the excel file and reset the variable, but the message persisted. So, the page is not being reprocessed after the excel process.

So, what I need to find is a way to force the page to reload completely after the Excel file has been processed. FYI: I have the PHP.INI file setting: Output_Buffering to ‘ON’.

I hope this makes sense to you, if not, I can try to clarify as best I can.

[php]
[size=8pt]<?php

include_once $_SERVER[‘DOCUMENT_ROOT’] .
‘\inc\magicquotes.inc.php’;
include_once $_SERVER[‘DOCUMENT_ROOT’] .
‘/inc/base.inc.php’;
include_once $_SERVER[‘DOCUMENT_ROOT’] .
‘/admin/export/excel-xml.php’;
$frmErrorLevel=0;
$frmErrMsg=’’;

if(isset($_POST[‘action’]) && $_POST[‘action’]==‘submitted’)
{
$carrierRatesdisabled=true;

  if(isset($_POST['ExportCarrier']))
  {
      exportTruckingCompanies();
  }
  if(isset($_POST['ExportDropFees']))
  {
      exportDropFees();
  }
  if(isset($_POST['ExportDomesticRates']))
  {
      if(isset($_POST['Carrier_Name']) && $_POST['Carrier_Name'] == "0")
      {
          $frmErrorLevel=3;
      }
      else
      {
        exportDomesticRates($_POST[Carrier_Name]);
      }
  }
  if(isset($_POST['ExportCanadianRates']))
  {
      exportCanadianRates();
  }
  if(isset($_POST['ExportFuelSurcharge']))
  {
      exportFuelCurchargeRates();
  }

}
else
{
$carrierRatesdisabled=true;
}

// get the carrier recordset for the drop list

$sql = 'SELECT * FROM Carriers order by CarrierName';
openRecordset($sql,$result, $link);
if($result)
{
while ($row = mysqli_fetch_array($result))
{
$carrierNames[] = array(‘id’ => $row[0], ‘name’ => html($row[1]));
}
mysqli_free_result($result);
close_mysql($link);
}
else $frmErrorLevel=1;
if (ob_get_length()){
@ob_flush();
@flush();
@ob_end_flush();
}
include ‘form.html.php’;
exit();
?>[/size]
[/php]

Excel output header information:
[php]
function save($filename, $download=false, $download_filename="")
{
if (!$download)
{
return $this->domXML->save($filename);
}
elseif ($this->domXML->save($filename))
{
$FileInfo = pathinfo(filename);
// fix for IE catching or PHP bug issue
header(“Pragma: public”);
header(“Expires: 0”); // set expiration time
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);
// browser must download file from server instead of cache
// force download dialog
header(“Content-Type: application/force-download”);
header(“Content-Type: application/octet-stream”);
header(“Content-type: application/x-msexcel”);
header(“Content-Type: application/download”);
// use the Content-Disposition header to supply a recommended filename and
// force the browser to display the save dialog.
if ($download_filename == “”)
$download_filename = “download.xls”;
header(“Content-Disposition: attachment; filename=”.$download_filename.";");
header(“Content-Transfer-Encoding: binary”);
header("Content-Length: ".filesize($filename));
@readfile($filename);
return true;
}
return false;
}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service