Page 1 of 1

Save current page as an html file?

Posted: Sat Feb 21, 2004 4:54 pm
by coyour1
Can someone explain to me some way using php to save the current page as an html file. Here is actually what I'm trying to do:

I've already create a page with a large form where the user can enter in variables and at the end of the form click sumbit, and right below the form is an iframe which displays the resulting page. The resulting page is created by a php script that creates a neatly formatted final page with all their variables entered in it. Now, here is where I need help. Is there some way I can create a button that allows the user to click it and have the newly created page (the resulting page in the iframe) automatically get saved on there computer, or maybe even just a prompt to allow athem to save this new html file on their computer?

If you have any ideas please let me know. Thank you.

Ben Coyour

Posted: Sat Feb 21, 2004 8:10 pm
by Albright
The first step would be to write a function that does everything that the code that builds the page in the iframe does, but instead of sending it to the screen, it sends it to a file. As for how to tell the client's web browser to download that file, I'm not sure... Relocating the browser to that file and telling the user to use the Save function in their browser would be an inelegant solution.

Posted: Sat Feb 21, 2004 8:56 pm
by evilMind
Use header and Content Disposition to tell the client to save a file.

eg:
header('Content-type: text/html');
header('Content-Disposition: attachment; filename="pageName.html"');

see [php_man]header[/php_man] manual page and http://www.faqs.org/rfcs/rfc2183 for more information about the content-disposition header(s)