Page 1 of 1
Save page to file
Posted: Mon Feb 06, 2006 10:27 am
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.
Posted: Mon Feb 06, 2006 10:31 am
by feyd
Posted: Mon Feb 06, 2006 10:54 am
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
Posted: Mon Feb 06, 2006 11:26 am
by feyd
Posted: Sun Feb 12, 2006 7:11 am
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
Posted: Sun Feb 12, 2006 11:44 am
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.
Posted: Sun Feb 12, 2006 11:48 am
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
Posted: Sun Feb 12, 2006 12:03 pm
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?
Posted: Sun Feb 12, 2006 12:44 pm
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.