annotate save.php @ 1313:c8317e07c15f

Merge into dev_main
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Mon, 22 Feb 2016 12:19:43 +0000
parents 3abbe1cc81ca cc55cc323592
children 47bfd9594617
rev   line source
nickjillings@1306 1 <?php
nickjillings@1306 2 header('Access-Control-Allow-Origin: *');
nickjillings@1306 3 header("Content-type: text/xml");
giuliomoro@1304 4 error_reporting(0);
nickjillings@1306 5 $postText = file_get_contents('php://input');
nickjillings@1306 6 $sha1_hash = sha1($postText);
nickjillings@1306 7 $datetime = date('ymdHis');
nickjillings@1306 8 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
nickjillings@1306 9 $fileHandle = fopen("saves/".$xmlfile, 'w');
nickjillings@1306 10 if ($fileHandle == FALSE)
nickjillings@1306 11 {
nickjillings@1306 12 // Filehandle failed
nickjillings@1306 13 $xml = '<response state="error"><message>Could not open file</message></response>';
nickjillings@1306 14 echo $xml;
nickjillings@1306 15 return;
nickjillings@1306 16 }
nickjillings@1306 17 $wbytes = fwrite($fileHandle, $postText);
nickjillings@1306 18 if ($wbytes == FALSE)
nickjillings@1306 19 {
nickjillings@1306 20 // FileWrite failed
nickjillings@1306 21 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nickjillings@1306 22 echo $xml;
nickjillings@1306 23 return;
nickjillings@1306 24 }
nickjillings@1306 25 fclose($fileHandle);
nickjillings@1306 26
nickjillings@1306 27 // Return JSON confirmation data
nickjillings@1306 28 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nickjillings@1306 29 echo $xml;
nickjillings@1306 30 ?>