JSON to File example


(Hans-Gerd Claßen) #1

Hi,

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)


Store variables in a text file
Tips and Tricks of the Month
Save a small database on hype
Tips and Tricks of the Month
Knowledge base: Guides from the Tumult Team
How do I implement PHP to work with hype projects?
(strmiska) #2

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 ?


(Hans-Gerd Claßen) #3

yes,

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


(strmiska) #4

thanx-working, too! :sunny:


(Mark Hunte) #5

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


(Mark Hunte) #6

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) {
              console.log(data);
              }).fail(function() {
                      console.log("Something went wrong with the request!");
                      });

(Stephen G) #7

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.