0

The following code used in productlist.php

// some code manipulation to generate new values
$filetodownload = 'DoubleClick to run.txt';
$filehandler=fopen($filetodownload,"w");
fwrite($filehandler,$generatedValue);
fclose($filehandler);
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));
ob_clean();
flush();
readfile($filetodownload);
header('Location:druglist.php');

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

2
Contributors
2
Replies
13
Views
4 Years
Discussion Span
Last Post by venkyb47
0

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.
    evt.preventDefault();

    // Open the file download in a new window. (It should just
    // show a normal file dialog)
    window.open(this.href, "_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);
This question has already been answered. 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.