JSON to File example


this is a simple setup to collect some data and store it as JSON in a txt-file on a server.
Makes use of jquery to access a small php-script which writes the file … and should give you a good start.

Usecase: e.g. store playerdata of a hypegame :smile:

permissions: php should be 644, filesdirectory should be 766 (for testing you may use 777)

JSON_To_File.zip (168.2 KB)


yes, it´s working - thank you.
question - it places per new user each a new text file. is it possible to enter a new user with a new score in the same text- file ?


change the php-file from write to append … means switch ‘w’ to ‘a’ …

thanx-working, too! :sunny:

This is cool.

Thanks Hans,

I put this on ISP server space ( public_html) in a directory. The myFiles directory remains 0755 , even when I change it it reverts back. But it does seem to work with now problem.

Three things.

1,I am curious though is there any risks having a writable php and what not on the server and is there anything I need to do to make sure I stay secure.

2, I assume the 0755 is so the world can access the folder and in the case of a directory execute means open.

3, How do you read the file back?

By the way I will be nominating this as a Tips and Tricks of the Month. August 2015

Think I found how to initially read the file back from the server.

In a new function call by a button action:

var currFileName = hypeDocument.getElementById('fileName').value + '.txt';	
	var full = "myFiles/" + currFileName;
  $.getJSON(full, function(data) {
              }).fail(function() {
                      console.log("Something went wrong with the request!");

I know this is an old post but should this still work or is there an updated way to to the same? Can’t get the sample to run on my server.

Any help greatly appreciated.

1 Like