annotate 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
rev   line source
nickjillings@1303 1 <?php
nickjillings@1303 2 try{
nickjillings@1303 3 date_default_timezone_get();
nickjillings@1303 4 }
nickjillings@1303 5 catch(Exception $e){
nickjillings@1303 6 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini
nickjillings@1303 7 }
nickjillings@1303 8 header('Access-Control-Allow-Origin: *');
nickjillings@1303 9 header("Content-type: text/xml");
nickjillings@1303 10 error_reporting(0);
nickjillings@1303 11 $postText = file_get_contents('php://input');
nickjillings@1303 12 $sha1_hash = sha1($postText);
nickjillings@1303 13 $datetime = date('ymdHis');
nickjillings@1303 14 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
nickjillings@1303 15 $fileHandle = fopen("saves/".$xmlfile, 'w');
nickjillings@1303 16 if ($fileHandle == FALSE)
nickjillings@1303 17 {
nickjillings@1303 18 // Filehandle failed
nickjillings@1303 19 $xml = '<response state="error"><message>Could not open file</message></response>';
nickjillings@1303 20 echo $xml;
nickjillings@1303 21 return;
nickjillings@1303 22 }
nickjillings@1303 23 $wbytes = fwrite($fileHandle, $postText);
nickjillings@1303 24 if ($wbytes === FALSE)
nickjillings@1303 25 {
nickjillings@1303 26 // FileWrite failed
nickjillings@1303 27 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nickjillings@1303 28 echo $xml;
nickjillings@1303 29 return;
nickjillings@1303 30 }
nickjillings@1303 31 fclose($fileHandle);
nickjillings@1303 32
nickjillings@1303 33 // Return JSON confirmation data
nickjillings@1303 34 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nickjillings@1303 35 echo $xml;
nickjillings@1303 36 ?>