Failing Navigation After Download

Posted on 2012-08-16
Medium Priority
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" "http://www.w.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w.org/1999/xhtml">
<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
  • 3
LVL 13

Assisted Solution

themrrobert earned 800 total points
ID: 38303195
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=http://www.mypage.com/"> 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

ID: 38305291

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 111

Accepted Solution

Ray Paseur earned 1200 total points
ID: 38309691

Author Comment

ID: 38368806
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

ID: 38368815
Thanks to both of you!

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

809 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