Failing Navigation After Download

Posted on 2012-08-16
Last Modified: 2012-09-05
Hi, all!

Have built a page that creates a .zip file in a temp folder, then opens that file to be downloaded by the user.  This page can be accessed by a user that is logged in or by using a link (with parameter) in an email that comes directly to this page.

File creates and downloads fine but, after downloading, it will not reload the page or even allow me to use header("Location: ..") to go to another page.  It just sits there, staring at me like I'm the idiot I am, while the objective is to show a dialog with a message after a successful download, then selectively go to another page.

In the attached code there is a function AddHistory() following the download and it is working correctly, adding the download history record.  This indicates that processing is continuing after the download is done.  However, I can't get the page to reload so I can't confirm that anything else is happening, only what is NOT happening.  It's like it dies when it hits the HTML.

Betting it's due to the download headers, but I don't have enough experience to know and couldn't find any direct references to that symptom in my online search.  Can confirm that there is no output (html, echo) before the download headers.

Windows Server, PHP 5.3.5, Apache

Code snippet follows.  The "$mode" stuff was added as I was trying to expirament my way around the problem using the header("Location: ).

Any help/ideas appreciated!


            if ($action != 'cancel') {            
            //      Open the file for downloading.
                  if (file_exists($zipfileF)) {
                        header('Content-Description: File Transfer');
                        header('Content-Type: application/zip');
                        header('Content-Disposition: attachment; filename="' . $zipName . '.zip' . '"');
                        header('Content-Transfer-Encoding: binary');
                        header('Expires: 0');
                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                        header('Content-Length: ' . filesize($zipfileF));
                        HistoryAdd($ord_id, "Downloaded");
                        $mode = 'success';
                  } else {
                        $mode = 'bad';
                  header("Location: aisDownloadOrder.php?delID=" . $delID . "&mode=" . $mode);
                  die("past redirect");


if ($mode > '') {
      $action = "cancel";
      if ($mode == 'success') $msg = 'Please verify that you have the file.';
      else $msg = 'Contact Tech Support if you need assistance.';

if ($action == "cancel") {
      // Go to Home or return to the previous page.
      if ($_SESSION['sn_nosession'] == "Yes") $lnk = "index.php";
      else $lnk = PageGet();
      $action = "goto";


<!DOCTYPE html PUBLIC "-//WC//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Expires" content="0">
<meta name="ROBOTS" content="NOINDEX,NOFOLLOW">

<title>Download Order</title>

<script language="javascript" src="aisInclude.js"></script>

<script type="text/javascript">

var actn = "<?php echo $action;?>";
var lnk = "<?php echo $lnk;?>";
var msg = "<?php echo $msg;?>";

if (msg > '') alert(msg);

if (actn == "goto" && lnk > '') {

Question by:springthorpeSoftware
    LVL 13

    Assisted Solution

    This is one of those times it's ok to use an iframe.

    The download page links to an iframe that loads the php page that does all the headers and downloading.  the page echos html, including a <META HTTP-EQUIV=Refresh CONTENT="10; URL="> along with <iframe src="phpdl.php" style="visibility: hidden;"></iframe>

    or if you want to get fancy you could do
    <script type="text/javascript" src="jqueryXX.js"></script>
    <script type="text/javascript">
    $(function {

    Author Comment


    Thanks for replying!!

    I'm an old database guy and fairly new to web front ends, so please bear with what is probably a stupid question:

    Is the iframe supposed to be placed on the page where the user selects which docs to download and clicks to get them or is it on a second (pop-up) page that opens when the "download" button is clicked?  Seems to me that, if it's on the same page, it would try to execute as soon as the "select" page was opened, before they could pick which docs they want included.

    LVL 107

    Accepted Solution


    Author Comment

    Thanks for replying!  The stackoverflow page would have solved the problem if I hadn't used a different approach.
    Instead of having the download automatically start, I display a link to the .zip file.  Just clicking that link starts the download process and avoids the "security" messages from most of the browsers that happens when you do it automatically.
    MUCH simpler than adding all of the code to do it automatically.

    Author Closing Comment

    Thanks to both of you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
    If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
    The viewer will learn how to dynamically set the form action using jQuery.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now