annotate save.php @ 1207:c3a180d49239

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