...

View Full Version : PHP to Mimic Browser "Save As" Feature



jakerbug
02-23-2007, 05:54 AM
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/default.asp?url=/workshop/author/behaviors/reference/behaviors/savesnapshot.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
include 'start.php';
?>
The HTML...


<?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...

mlseim
02-23-2007, 02:22 PM
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.

jakerbug
02-23-2007, 04:06 PM
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/jakerbug/budget/styles2.css



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum