By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,716 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,716 IT Pros & Developers. It's quick & easy.

Saving a page into html in php

P: 28
I ahve a problem..Help me....

When user submits a form, a page is displayed with all the submitted details. But my real problem is how do i save the same page into .htm/.html format and store it on the disc at the same time when the user sees the page...Thanks...
Jan 30 '07 #1
Share this Question
Share on Google+
5 Replies


Atli
Expert 5K+
P: 5,058
You can save all your output by doing something like this.

[PHP]<?php

// Set the path to the file you want to save
$filename = "Path to the file you want to save";
// Note: This does not create any folders, they must exists before you do this.

// Function to handle the output on flush
function ob_flush($buffer)
{
// Open your file and write the buffer
$fh = fopen($filename, "w");
fwrite($fh, $buffer);
fclose($fh);

// print the buffer to the browser
print $buffer;
}

// Start buffering the output
ob_start("ob_flush");

/** Whatever you want to output, put it here. **/

// Stop buffering and send the buffer to the ob_flush function
ob_end_flush();

?>[/PHP]

Hope this helps
Jan 30 '07 #2

P: 28
Thanks... for your reply.....But thisn't what i mean

The above code is for already existing file. But this isn't what i mean. I have to save the page at the same time the user is viewing the page. For example if u r looking some web page and then itself u can save the page using SaveAs in your desired format like doc/rtf/html etc. I want that kind of saving using php.
Jan 30 '07 #3

Atli
Expert 5K+
P: 5,058
You want the user to be able to save the page he's viewing to his hard drive?

Im not sure thats possible. That would require the code to have access to the users local drive, and that poses a major security threat.
Jan 30 '07 #4

ronverdonk
Expert 2.5K+
P: 4,258
You would not want to write to the user's pc! As Atli says, you run a huge security risk when it is possible for servers writing files to clients. Hackers heaven!

The usual procedure is to either let the user print his screen, using a screen button with a javascript print command, or send an email with the data.

Ronald :cool:
Jan 30 '07 #5

Motoma
Expert 2.5K+
P: 3,235
There are ways to make pages bring up a Save File dialog instead of rendering in your browser, but it doesn't sound like that is what you want.

If this is what you are looking for, post back, and I will give you some code.
Jan 30 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.