annotate save.php @ 749:07c996307cbd

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