I'm working on a quick download script that gathers visitor info and logs it in a Mysql table when they try to download a file.
The download link on the page triggers a Greybox 'popup' window and runs a PHP script that checks for the presence of a cookie, shows a form if needed, stores info in the table and finally does the download itself. .
Currently the file download itself is handled by a header("Location:<path to file>") function. I'm aware this may not be the best way to do it but it does what I need for now.
However, this means that I can't output anything to the browser once the header call is made.
The problem is that I need to close the Greybox window with some Javascript but I can't output the necessary code because the header is already sent.
So I'm trying to use output buffering but not having much luck.
For the purposes of this question, let's assume I just want to output something to the browser AND download the file.
How might I do this?
Currently I have something like
Which plainly won't work. I thought with output buffering I could do
I've been trying to read up on Output Buffering but I'm not having much luck. I can't find an example that does what I'm trying to do - they all seem to revolve around replacing text within the output buffer.
--
Tek-Tips Forums is Member Supported. Click Here to donate
<honk>*:O)</honk>
Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
The download link on the page triggers a Greybox 'popup' window and runs a PHP script that checks for the presence of a cookie, shows a form if needed, stores info in the table and finally does the download itself. .
Currently the file download itself is handled by a header("Location:<path to file>") function. I'm aware this may not be the best way to do it but it does what I need for now.
However, this means that I can't output anything to the browser once the header call is made.
The problem is that I need to close the Greybox window with some Javascript but I can't output the necessary code because the header is already sent.
So I'm trying to use output buffering but not having much luck.
For the purposes of this question, let's assume I just want to output something to the browser AND download the file.
How might I do this?
Currently I have something like
Code:
echo("Download complete");
header("Location:/downloads/".$fileinfo['url']);
exit;
Which plainly won't work. I thought with output buffering I could do
Code:
ob_start();
print("Download complete");
header("Location:/downloads/".$fileinfo['url']);
exit;
ob_end_flush(); // moot since the script exits and the buffer is flushed
I've been trying to read up on Output Buffering but I'm not having much luck. I can't find an example that does what I'm trying to do - they all seem to revolve around replacing text within the output buffer.
--
Tek-Tips Forums is Member Supported. Click Here to donate
<honk>*:O)</honk>
Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.