comparison save.php @ 1303:ade3acb0cee3

Added score_parse.php separators for CSV
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Tue, 23 Feb 2016 17:11:28 +0000
parents
children 124e6c702845
comparison
equal deleted inserted replaced
-1:000000000000 1303:ade3acb0cee3
1 <?php
2 try{
3 date_default_timezone_get();
4 }
5 catch(Exception $e){
6 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini
7 }
8 header('Access-Control-Allow-Origin: *');
9 header("Content-type: text/xml");
10 error_reporting(0);
11 $postText = file_get_contents('php://input');
12 $sha1_hash = sha1($postText);
13 $datetime = date('ymdHis');
14 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
15 $fileHandle = fopen("saves/".$xmlfile, 'w');
16 if ($fileHandle == FALSE)
17 {
18 // Filehandle failed
19 $xml = '<response state="error"><message>Could not open file</message></response>';
20 echo $xml;
21 return;
22 }
23 $wbytes = fwrite($fileHandle, $postText);
24 if ($wbytes === FALSE)
25 {
26 // FileWrite failed
27 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
28 echo $xml;
29 return;
30 }
31 fclose($fileHandle);
32
33 // Return JSON confirmation data
34 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
35 echo $xml;
36 ?>