annotate save.php @ 1115:ddc5a639179a

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