annotate save.php @ 813:f452455b5977

Resolved #1394: Python returns same XML responses as the PHP server
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Fri, 27 Nov 2015 12:09:49 +0000
parents
children 2647dd909229 b5bf2f57187c 9ee921c8cdd3
rev   line source
nicholas@813 1 <?php
nicholas@813 2 header('Access-Control-Allow-Origin: *');
nicholas@813 3 header("Content-type: text/xml");
nicholas@813 4 $postText = file_get_contents('php://input');
nicholas@813 5 $sha1_hash = sha1($postText);
nicholas@813 6 $datetime = date('ymdHis');
nicholas@813 7 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
nicholas@813 8 $fileHandle = fopen("saves/".$xmlfile, 'w');
nicholas@813 9 if ($fileHandle == FALSE)
nicholas@813 10 {
nicholas@813 11 // Filehandle failed
nicholas@813 12 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@813 13 echo $xml;
nicholas@813 14 return;
nicholas@813 15 }
nicholas@813 16 $wbytes = fwrite($fileHandle, $postText);
nicholas@813 17 if ($wbytes == FALSE)
nicholas@813 18 {
nicholas@813 19 // FileWrite failed
nicholas@813 20 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nicholas@813 21 echo $xml;
nicholas@813 22 return;
nicholas@813 23 }
nicholas@813 24 fclose($fileHandle);
nicholas@813 25
nicholas@813 26 // Return JSON confirmation data
nicholas@813 27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nicholas@813 28 echo $xml;
nicholas@813 29 ?>