473,287 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Download Then Redirect

I wonder if anyone can help me out with this. I am sending the user to a download page where when they click on the download button the file is downloaded and then I want the user redirected after the file download to a confirmation page.

My download processing page is as follows:

[PHP]<?php

$mytalk = $_GET['varrqust'];

if($_GET['varrqust'] == "1"):
$mytalk = 'Talk 1';
$talksize = 3Mb';
$talkpath = 'talk1.pdf';

elseif($_GET['varrqust'] == "2"):
$mytalk = 'Talk 2';
$talksize = '3Mb';
$talkpath = 'talk2.pdf';

elseif($_GET['varrqust'] == "3"):
$mytalk = 'Talk 3';
$talksize = '3Mb';
$talkpath = 'talk3.pdf';

endif;

$path = $talkpath;
$file = basename($path);
$size = filesize($path);

//do download
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$file");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $size");

@readfile($path);

header("Location: sbx_dwnldthx.php?varrqust=$varrqust"); /* Redirect browser */

exit();

?>[/PHP]

In this instance the file is downloaded as expected but the user doesn't get redirected.

If I change the order of the last few lines of code as follows:

[PHP]<?php

..........

header("Location: sbx_dwnldthx.php?varrqust=$varrqust"); /* Redirect browser */

@readfile($path);

exit();

?>[/PHP]

The user gets redirected as required but the file doesn't get downloaded!

Can someone please explain where I am going wrong.

Thanks in advance.
Oct 11 '07 #1
4 8567
t0m66
6
You could use some JavaScript to open the download file in a popup window then have the 'Thanks!' page on the current page, although I don't think this is the appropriate section, the following code might help:

[html]
<script type="text/javascript">
function download() {
var w = window.open("http://path/to/download.ext", "", "width=100,height=100,scrollbars=no,status=no" );
}

function thanks() {
document.getElementById('thanks').style.display = 'block';
}
</script>

<input type="button" onclick="download(); thanks(); " value="Download file" />

<div id="thanks" style="display: none">
your thanks message here
</div>

[/html]
Oct 11 '07 #2
Thanks for your reply, t0m66. Is there any way to achieve the redirection just using PHP, as I would prefer to avoid generating pop-up pages if possible?

Thanks again.
Oct 11 '07 #3
t0m66
6
Thanks for your reply, t0m66. Is there any way to achieve the redirection just using PHP, as I would prefer to avoid generating pop-up pages if possible?

Thanks again.
I don't know of one, although there is the possibility of using a Location: header to redirect them to the download, although I don't think you could put some 'Thanks' message there too.
Oct 11 '07 #4
I'm trying to use

header ("Location: - see initial code

as it is without any apparet success. It is almost as if as soon as I use it either wants to stop everthing else working or it is prevented from running by the other code purely depending upon its position! And doesn't appear to be any happy medium.

Thanks again for your input.
Oct 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Matthew Sims | last post by:
Is it possible to force a download without using the readfile function? My website setup consists of my server that serves the web pages plus a high-speed file server elsewhere on the internet...
4
by: Trigger | last post by:
I'm trying to build a tray for users to download their selected items. I was wondering if anyone knows how to response.redirect a file (for the user to download) and check to see if the download...
9
by: Glen | last post by:
I'm writing a console utility to download specific files from web sites based on the command line options. In most cases, I can trap the 404 error when the file isn't available because the...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
4
by: Hitesh | last post by:
Hi, I am having a requirement where in user can click on a link and the download popup appears and then user should be redirected to a congratulations page. We didn't bother whether the...
2
by: Jan Paul van de Berg | last post by:
I have a piece of software that people can download and a third party promoting that software. In order for them to be able to count the number of downloads, I have to put a tracking code on my...
5
by: Khafancoder | last post by:
Hi guys, i am building a FileSharing website, i wanna allow users to be able using download managers such as DAP to download files from webserver but don't allow them to retrive files url......
9
by: Matt Nunnally | last post by:
I have a form which allows the user to download a simple text file. They click on the download button and it brings up the "Save As" dialog. Once they save the file, I want them to be redirected to...
6
by: vstud70 | last post by:
Dear friends, I have a website that sells software. In my download page I have a "download" button that once the user clicks it open the windows wizard to /download/save/cancel the software. So...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.