tags:

views:

61

answers:

4

I got a script like this

<?php

if (file_exists("./foo.txt")) {

    header("Content-type: application/force-download");
    header("Content-length: ".filesize("./foo.txt"));
    header('Content-Disposition: attachment; filename="foo.txt"');
    readfile('./foo.txt');
}

print "HEY!";

?>

and I want the "Hey" to be written to the page after the forced download, how is that possible?

I see download pages that are like "If your download does not start automatically click here", so it's content and the download? The hey in my example is included in the text file, so it doesn't work.

A: 

This is not possible this way. (At least as long as we don't have multi-part requests.)

The pages you mention redirect to the "if your download does not start...." page, and trigger the download from there, usually using JavaScript to open the download in a new window.

Pekka
+2  A: 

Display the message on another page .. then provide a link to download the file or redirect the browser to the php file that forces the download ..

dejavu
+2  A: 

This would only be possible with a multipart message. But unfortunately there are not many browser that support multipart messages in HTTP (I think Opera is the only one).

That’s why it’s common practice to send the download page with a meta refresh redirect to have both a textual message and a download action (although it’s in the opposite order).

Gumbo
A: 

You can do it with META REFRESH like this:

<meta http-equiv=REFRESH CONTENT="5; url=http://your_domain/your_file"&gt;
fabrik