473,467 Members | 1,291 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Download Then Redirect

27 New Member
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 8607
t0m66
6 New Member
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
ridgedale
27 New Member
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 New Member
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
ridgedale
27 New Member
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.