The following code used in productlist.php

// some code manipulation to generate new values
$filetodownload = 'DoubleClick to run.txt';
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$filetodownload);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filetodownload));

After file downloaded page not redirecting to druglist.php page. Page remains at productlist.php page

Recommended Answers

All 2 Replies

You are redirecting the wrong request. The request you are showing there is the one that downloads the file. It doesn't show any content to the browser; it just downloads a file. Redirecting it wouldn't have any effect.

What you need to do is redirect the page that triggers the download; the one where the link/script that sends the request for the download is.

For instance, if a link is being used to trigger the download, this JavaScript code would trigger the download, and then redirect the current page do a new location.

// Capture the "click" event of the link.
var link = document.getElementById("the-link");
link.addEventListener("click", function(evt) {
    // Stop the link from doing what it would normally do.

    // Open the file download in a new window. (It should just
    // show a normal file dialog), "_blank");

    // Then redirect the page you are on to whatever page you
    // want shown once the download has been triggered.
    window.location = "/thank_you.html";
}, true);

Good solution Atli.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.