annotate save.php @ 1118:3edcbbea168b

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