annotate save.php @ 1457:c8a9825aaa05

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