Save current page as an html file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
coyour1
Forum Newbie
Posts: 1
Joined: Sat Feb 21, 2004 4:54 pm

Save current page as an html file?

Post 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
User avatar
Albright
Forum Newbie
Posts: 20
Joined: Sat Sep 13, 2003 8:03 pm
Contact:

Post 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.
evilMind
Forum Contributor
Posts: 145
Joined: Fri Sep 19, 2003 10:09 am
Location: Earth

Post 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)
Post Reply