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 Coder
    Join Date
    Mar 2004
    Location
    New Jersey
    Posts
    70
    Thanks
    2
    Thanked 1 Time in 1 Post

    PHP to Mimic Browser "Save As" Feature

    Ok - I've spent enough hours searching that this warrents a "can it even be done" post...

    I converted an Excel file, complete with formulas and self-calculating cells, into a web page using javascript. It's a personal budget and it allows me to change the value of certian cells and basically behave exactly the same way it does in Excel. The problem is saving the file.

    I figured out how to save an updated version on the HTML file locally using persistence (http://msdn.microsoft.com/library/de...esnapshot.asp). This successfully saves any changes I make in any of the input fields on the page, using the borwser's "Save As" function. The trick now is to get these changes to save on the server.

    I've used this code in the past to save the output of a dynamically generated page:

    PHP Code:
    <?php
    include 'start.php';
    ?>
    The HTML...

    PHP Code:
    <?php
    $page_source 
    ob_get_contents(); 
    ob_end_flush(); 
    $unique_id date("y-m-d_g:i:sa",time());
    $file $unique_id.".php"
    $fp fopen ("$file""wb"); 
    $content "$page_source"
    fwrite($fp$content); 
    fclose($fp); 
    ?>
    BUT...

    a) I don't know how to call this script from a "Save" button, or something like that, and
    b) Since I don't know how to do that, I don't even know if the file generated would include the updated input fields, or just the original HTML. (When I "View Source" on the page after updating input fields, the orignal HTML appears - if that helps... is that what the PHP script would see?)

    If anyone can tell me if this is possible, either my way or another way, it would save me another 10 or so hours of Google-ing. (And if it is possible, does anyone know how to pass the updated HTML page through a PHP processor to save it on the server...?)

    Thanks!

    P.S. - As I mentioned, this for my own personal budget, so I'd don't want to link to the file I'm working on if someone can figure out what I'm talking about without it. If not, I'll make a non-sensitive version for everyone to see...

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,493
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Have you thought about saving the cell contents themselves and
    not the HTML? Even using a flat-file text database to save all cells?

    Then, the PHP script reads all of the cell contents from the text file
    and populates the cells on your page. I guess a key thing here is also
    how many cells you have ... how many variables? I'm sort of thinking
    you could use all PHP and no Javascripting.

  • #3
    New Coder
    Join Date
    Mar 2004
    Location
    New Jersey
    Posts
    70
    Thanks
    2
    Thanked 1 Time in 1 Post
    I'd thought about doing it that way, but it seemed a little time-consuming. I just thought there was probably an easier way. Also, what I ultimately wanted was to be able to view a directory of all my timestamped files and click on the one I wanted to work with. This way if I ever made a mistake, I could just start over with an older version.

    All that said, if populating the cells from a TXT file is the best way to do it, than so be it. Eliminating the Javascript is kind of out of the question though, first of all because the page updates client-side in real time, but mostly because it was generated by a program and I'd have no idea how to even begin translating what it produced. I'm also not terribly interested in writing my own script to do the calculations (that's why I got the program!)

    Here's a link to a sample I made: http://mywebpages.comcast.net/jakerbug/budget/index.htm

    Let me know if that changes things at all - if it's easier or harder to do what I'm envisioning, or if the solution above will or won't work with this.

    Also, here's the links to the JS and CSS files, if that helps:
    http://mywebpages.comcast.net/jakerbug/budget/calc2.js
    http://mywebpages.comcast.net/jakerb...et/styles2.css


  •  

    Posting Permissions

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