annotate save.php @ 347:50117a4ea276 Dev_main

Feature #1270 completed. Outside reference works as designed
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Mon, 23 Nov 2015 10:47:02 +0000
parents e40eb1c67933
children b448ed356355 888292c88c33
rev   line source
n@292 1 <?php
b@343 2 header('Access-Control-Allow-Origin: *');
nicholas@345 3 header("Content-type: text/xml");
n@292 4 $postText = file_get_contents('php://input');
n@292 5 $datetime = date('ymdHis');
n@292 6 $xmlfile = "save".$datetime.".xml";
n@292 7 $fileHandle = fopen("saves/".$xmlfile, 'w');
nicholas@345 8 if ($fileHandle == FALSE)
nicholas@345 9 {
nicholas@345 10 // Filehandle failed
nicholas@345 11 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@345 12 echo $xml;
nicholas@345 13 return;
nicholas@345 14 }
nicholas@345 15 $wbytes = fwrite($fileHandle, $postText);
nicholas@345 16 if ($wbytes == FALSE)
nicholas@345 17 {
nicholas@345 18 // FileWrite failed
nicholas@345 19 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nicholas@345 20 echo $xml;
nicholas@345 21 return;
nicholas@345 22 }
n@292 23 fclose($fileHandle);
nicholas@345 24
nicholas@345 25 // Return JSON confirmation data
nicholas@345 26 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nicholas@345 27 echo $xml;
n@292 28 ?>