Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Saving html file to server, using a URL

    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.

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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.
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,371
    Thanks
    11
    Thanked 591 Times in 572 Posts
    Quote Originally Posted by itsallkizza View Post
    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.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •