0

Hello all: I have a small script that will present options to a user, and from those options will export data into an Excel spreadsheet. This seems to work correctly, but the problem is that the user interface page does not get updated after the download.

Here is an example: I have an element on the form called $frmErrMsg, which I set to a text value and display it on the page. It is controlled by another variable called $frmErrorLevel(in this case it is set to either a 0 or 1). On initial page load I set the $frmErrorLevel variable to a 1 and the message displays.

When I process the Excel file, I reset the $frmErrorLevel = 0, but the message does not clear.

Obviously the form is not reloading after the Excel file is output (due to the extra header???). is there a better technique for handling this?

Here is some code:
(index.php)

<?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')
  {
       // this will call the ExcelXML.php scripts and output the data to Excel
       exportTruckingCompanies();
  }
   else $frmErrorLevel=1;
   $frmErrMsg = 'Error retrieving Carrier Data';
   include ('form.html.php');
   exit();
?>

here is the form.html.php

<?php   
        session_start();
        include_once $_SERVER['DOCUMENT_ROOT'] .'/inc/standardFunctions.inc.php'; 
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Export Trucking Data</title>
    </head>
    <body>
        <h1>Export Data</h1>
        <form action="" method="post">
        <?php   if($frmErrorLevel>0)
                {
                    echo '<font color=#CC6600 size=+1>'.$frmErrMsg.'</font><br><br>';
                }
        ?>
        <table width="650" border="0">
            <caption>
                <font size="+3">Data Export Options</font>
            </caption>
            <tr>
                <td>
                    <?php 
                        if($frmErrorLevel==1) print '<img src= ..\..\images\rdx.gif>'; 
                        else echo "&nbsp"; 
                    ?>
                </td>
                <td width="275">Carrier table data</td>
                <td width="100"><input name="ExportCarrier" type="submit" value="Submit"></td>
                <td> <div align="center"> &nbsp;</div></td>

            </tr>
        </table>
        <div>
            <input type="hidden" name="action" value="submitted" />
        </div>
    </form>
    </body>
</html>

and finally, the Excel output header

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;
    }
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jkon
0

What is \inc\magicquotes.inc.php and /inc/base.inc.php and /admin/export/excel-xml.php and /inc/standardFunctions.inc.php . Simplify your problem and the include files and you might get an answer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.