2

Problem:

I don't know the simplest way to allow a single web viewer to update data in a text file on a server. (ie. only 1 person will be changing the data.)

Objective:

To make a prototype web application just one person needs to input in the start and end dates of new assignments and locations of staff and the whole company can visualize the information on a GANTT chart, probably using this Jquery libary.

Constraints:

My data is about the equivalent size of 1000 of these javascript list of lists like

 *data = [["John Smith" , "assigment" , "1/1/10", "1/1/11", "Peru"],[...],...]* 

Employee assignment data must be on an internal server.

I can't use a database (such as SQlite or MySQL).

I can only use PHP, Javascript, and jQuery.

Fact: Javascript cant directly change a data file sitting on the server.

My tentative fuzzy solution:

On client-side: use jQuery getJSON() to pass the data back and forth between dataReadWriter.php.

On server-side: dataReadWriter.php modifies a PHP array as well as writes modified data and reads JSONdata.txt stored in a text file on our internal server.

Community
  • 1
  • 1
b_dev
  • 2,568
  • 6
  • 34
  • 43
  • 1
    Why can't you use a database...this is what they are for? You're probably going to end up having to create a flat-file database with serialized object and a php backend. – Eugene Oct 31 '10 at 01:52
  • 2
    this sounds eerily like a homework assignment... – jellyfishtree Oct 31 '10 at 02:12
  • this may be a similar concept to what you are trying to do http://stackoverflow.com/questions/2237291/reading-and-writing-configuration-files/2237315#2237315 – jellyfishtree Oct 31 '10 at 02:20
  • @jellyfishtress yes the answer to http://stackoverflow.com/questions/2237291/reading-and-writing-configuration-files/2237315#2237315 was helpful. Thanks. Especially this part: "store... an array and then either use serialize/unserialize or use var_export/include to use it." – b_dev Oct 31 '10 at 19:35

1 Answers1

1

Given the constraints, it can't be done a lot smarter than what you are suggesting. One thing though, you shouldn't overwrite the only file containing the data, at least switch back and forth between two files, and make sure that your program does not overwrite the other file if one of the files show any signs of being damaged. You can use a PHP session to keep track of which file is the most recent, but better have some in-file timestamps as a fallback.

Is there anything in particular that you worry about?

aaaaaaaaaaaa
  • 3,630
  • 1
  • 24
  • 23
  • Thanks. Is the reason I should use 2 files to ensure that 1 person does not overwrite another person's changes when they are overlapping one another in terms of reading and writing the file? To prevent overwriting each others changes I was thinking of giving permission to just 1 person to make changes. I am not sure I understand your question "Is there anything in particular that you worry about?" One worry is to make sure before I decide to start this that I dont burn too much time on this. Another worry is to ensure the code and data is simple for someone in future to use MySQL. – b_dev Oct 31 '10 at 19:51
  • Primarily, it's to keep the data safe if the server crashes during a write. Of course a database application would take care of such stuff for you. – aaaaaaaaaaaa Oct 31 '10 at 20:55