Reubencovington Posted November 27, 2014 Share Posted November 27, 2014 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 More sharing options...
Reubencovington Posted November 27, 2014 Author Share Posted November 27, 2014 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 More sharing options...
Recommended Posts