...

View Full Version : Saving html file to server, using a URL



1stCome
02-03-2009, 03:58 PM
Hi -

I have a two part question.

To paint a picture of what I'm trying to accomplish - There are forms on my site that need to be filled out by the user. Once the forms are complete and saved, the user is able to select a printable view of the form, which is a static html version of the form. What I'm trying to accomplish now is getting functionality on my site that allows users to save this html file to another place on the server, instead of on their machine. Essentially, it's a makeshift "snapshot" functionality.

The function that gives the user the printable page only returns the URL to the html page:

function printURL(){
try {
var printSmartForms = "SuperDuperWebsite/Project/PrintForms?Project=";
var printArgs = "&PrintBySection=False&PrintHeaderView=True&PrintHeaderInfo=True&PrintPageBreak=True&PrintLogo=True";
var printURL = UrlUtils.fullUrlFromUnsURL(("") + (printSmartForms + (this + printArgs)));
printURL = "<a href=" + printURL + " target=\"_blank\">[Print View]</a>";
return printURL;

}
catch (e) {
throw(e);
}
}

The first part of my question is - can I programmatically save the page from this URL, instead of from being on the actual page?

The second part is - How exactly would I save it to the server instead of to the machine?

Thanks in advance for any input.

itsallkizza
02-03-2009, 05:06 PM
1) Yes it's possible to save copies of html files to different parts of the server (though not with JS alone - you'll be needing some server-side code). However, I suggest you rethink your solution:

Instead of literally saving multiple copies of html files to various locations on the server, a better solution would be to store the user's inputted information in a database and then use a single control file to output the static form. You can use mod rewrite to allow custom urls.

For example, you could have a hidden php page in mysite.com/ that requests the data saved by the user from a database (or even a cookie if you don't want to mess with DBs) and then prints out the static form, behind the scenes.

When the user intially submits the form, you can have some server-side code create a target path for the user something like mysite.com/users/form_a.html which won't actually exist, but will instead redirect the user (again behind the scenes) to your php page.

As far as the user is concerned, they will appear to remain on mysite.com/users/mike_h/form_a.html. As far as you are concerned, you only have to modify/maintain a single central API and your server won't be bogged down with multiple softcopy html pages.

2) If you follow the above outline (or something similar) you avoid having to save any html files anywhere, so this won't be an issue.

rnd me
02-04-2009, 07:47 AM
1) Yes it's possible to save copies of html files to different parts of the server (though not with JS alone - you'll be needing some server-side code)

actually, you can save without server code.
PUT, a basic HTTP method will create files.

but it's a terrible idea to let someone save data without sanitizing it first, so i would not recommend allowing PUT for anon users.

at any rate, OP would be better off sanitizing fields of distinct info on the server, saving to a database.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum