annotate save.php @ 1113:9ee921c8cdd3

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