Jump to content

Phaser outputing to server text file


Reubencovington
 Share

Recommended Posts

I'm currently creating a small game in Phaser that I want to send time data saved to a textfile whenever a certain function is called.

//  Writes the current time to a new line in the output.txt text filefunction recordTime() {{  //File Output code goes here }        

What is the best way of doing this with phaser and javascript?

Link to comment
Share on other sites

Ok after a bit of fiddling I managed to get it working I think
 

    //File data test    var data = new FormData();    data.append("data" , logevent + " at " + Date() + "\n");    var xhr = new XMLHttpRequest();    xhr.open( 'post', '/output/php/filetest.php', true );    xhr.send(data);

I use a XML http request to send the log data to a simple php script that appends the data to the log file.

 

Php script:

<!DOCTYPE html><?php   if(!empty($_POST['data'])){      $data = $_POST['data'];      $fname = "upload\log.txt";      //appends to the log file and makes sure it can't be written by two programs at once      file_put_contents($fname, $data, FILE_APPEND | LOCK_EX);    }?>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...