annotate save.php @ 1816:27d44af3df3d

Merge from branch "WAC2016"
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Fri, 04 Dec 2015 10:57:39 +0000
parents 592c412ae87b
children b448ed356355 888292c88c33
rev   line source
b@1478 1 <?php
b@1508 2 header('Access-Control-Allow-Origin: *');
nickjillings@1510 3 header("Content-type: text/xml");
b@1478 4 $postText = file_get_contents('php://input');
b@1478 5 $datetime = date('ymdHis');
b@1478 6 $xmlfile = "save".$datetime.".xml";
b@1478 7 $fileHandle = fopen("saves/".$xmlfile, 'w');
nickjillings@1510 8 if ($fileHandle == FALSE)
nickjillings@1510 9 {
nickjillings@1510 10 // Filehandle failed
nickjillings@1510 11 $xml = '<response state="error"><message>Could not open file</message></response>';
nickjillings@1510 12 echo $xml;
nickjillings@1510 13 return;
nickjillings@1510 14 }
nickjillings@1510 15 $wbytes = fwrite($fileHandle, $postText);
nickjillings@1510 16 if ($wbytes == FALSE)
nickjillings@1510 17 {
nickjillings@1510 18 // FileWrite failed
nickjillings@1510 19 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nickjillings@1510 20 echo $xml;
nickjillings@1510 21 return;
nickjillings@1510 22 }
b@1478 23 fclose($fileHandle);
nickjillings@1510 24
nickjillings@1510 25 // Return JSON confirmation data
nickjillings@1510 26 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nickjillings@1510 27 echo $xml;
b@1478 28 ?>