I've asked about this before but could not get a working solution.

I have a database. Users put data in the DB :) I have a page with a list of accessible data "block". Each "block" has a button next to it.

When a user click a button what I would like is:

- I extract the data block from the DB
- I send the data to the browser as a file download so the user can save the data block to disk. (i.e. a save-file-as dialog comes up)
- I mark the data block as inaccessible
- I reload the page and present a new list. The data block the user as just selected is no longer in the list.


I have figure out how to force a file download using:

header("Content-disposition: attachment; filename=aFile");
header("Content-type: application");

The problem I have is that I need a way of send the user back to list page so I can regenerate a new listing. I can't use header("Location") because I've already started an output stream (the download).

Some suggested using this header:

header("Content-Type: multipart/mixed; boundary=\"-Boundary-12399\"");

But I could quite get it to work. The example code I have been trying to get to work make Netscape open a save-as dialog three times and on IE 6 just prints everything in the browser window. This is the code:

(suggested by Marek Kilimajer)
<?
header("Content-Type: multipart/mixed; boundary=\"-Boundary-12399\"");

print "---Boundary-12399\r\n";
print "Content-Type: text/html\r\n";
print "\r\n";

//HTML code goes here

print "\n";
print "---Boundary-12399\r\n";
print "Content-Type: application/octet-stream\r\n";
print "Content-Disposition: attachment; filename=foo.tar.gz\r\n\r\n";
readfile("./foo.tar.gz");

print "---Boundary-12399--\r\n";
print "\r\n";
?>


I'm sure someone has done this before :) What is the "correct" way to achieve this effect? Is multipart content-type the way to go?


Thanks,

Jean-Christian Imbeault

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to