Save page to 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
scs3rd
Forum Newbie
Posts: 16
Joined: Mon Jan 30, 2006 6:17 am

Save page to file

Post by scs3rd »

I need help with the following task.

Basically, what I want to do is to be able to write a whole php page to a file. Not the html tags etc., just the content.
This page could potentially be several hundred lines long.

My initial thoughts was to save the whole page into a variable and write the variable, but I can't really see how to do it.

Any help appreciated.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

scs3rd
Forum Newbie
Posts: 16
Joined: Mon Jan 30, 2006 6:17 am

Post by scs3rd »

file_get_contents() kind of does what I want it to do, but is there anyway it can include the actual values for the php variables, rather than the code?

Or will I need to do it another way?

Thanks for your replies
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

scs3rd
Forum Newbie
Posts: 16
Joined: Mon Jan 30, 2006 6:17 am

Post by scs3rd »

Okay I have this working, but is there a way for the user to specify a filename and a location for the file to be saved?

I found this javascript code snippet that launches a 'save as' dialogue box, which seems to be a much more elegant solution. The only problem is is doesn't work on Firefox under Windows or Linux.

Code: Select all

onclick="javascript: document.execCommand('SaveAs','1','Filename');"
Is there an equivalent piece of code in PHP?

Or does anyone know a fix for the above piece of javascript. (I know this isn't really the place to ask, but one of you web developers may have come across this problem.)

Thanks for any help
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Firefox doesn't allow access to that functionality due to security, among other things.

The Javascript solution allows only the user to save the page. Your original post lead me to believe you wanted to save the page to the server.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

scs3rd wrote:Okay I have this working, but is there a way for the user to specify a filename and a location for the file to be saved?

I found this javascript code snippet that launches a 'save as' dialogue box, which seems to be a much more elegant solution. The only problem is is doesn't work on Firefox under Windows or Linux.

Code: Select all

onclick="javascript: document.execCommand('SaveAs','1','Filename');"
Is there an equivalent piece of code in PHP?

Or does anyone know a fix for the above piece of javascript. (I know this isn't really the place to ask, but one of you web developers may have come across this problem.)

Thanks for any help
Control+S
scs3rd
Forum Newbie
Posts: 16
Joined: Mon Jan 30, 2006 6:17 am

Post by scs3rd »

The Javascript solution allows only the user to save the page.
Sorry if it was unclear, yes I want the user to be able to save the page, specifying the filename and the location for it to be saved.

How would I do this in a way that was compatible with both IE and Firefox?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Without getting a signed script, you won't be able to do it in Firefox. Just give them information on how to save pages or something.
Post Reply