annotate save.php @ 1097:ebf52bf47fb7

Temporary fix of #1580. Updated schema in preparation of #1661, #1469 & #1649
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Thu, 10 Mar 2016 16:42:16 +0000
parents f4f9cde581aa
children ba6b9e1aaef5
rev   line source
n@1090 1 <?php
n@1090 2 error_reporting(0);
n@1090 3 header('Access-Control-Allow-Origin: *');
n@1090 4 header("Content-type: text/xml");
n@1090 5 $postText = file_get_contents('php://input');
n@1090 6 $file_key = $_GET['key'];
n@1090 7 $filename = "saves/save-".$file_key.".xml";
n@1090 8 $fileHandle = fopen($filename, 'w');
n@1090 9 if ($fileHandle == FALSE)
n@1090 10 {
n@1090 11 // Filehandle failed
n@1090 12 $xml = '<response state="error"><message>Could not open file</message></response>';
n@1090 13 echo $xml;
n@1090 14 return;
n@1090 15 }
n@1090 16 $wbytes = fwrite($fileHandle, $postText);
n@1090 17 if ($wbytes === FALSE)
n@1090 18 {
n@1090 19 // FileWrite failed
n@1093 20 $xml = '<response state="error"><message>Could not write file "'.$filename.'"</message></response>';
n@1090 21 echo $xml;
n@1090 22 return;
n@1090 23 }
n@1090 24 fclose($fileHandle);
n@1090 25
n@1093 26 // Return XML confirmation data
n@1093 27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"'.$filename.'"</file></response>';
n@1090 28 echo $xml;
n@1093 29 ?>