annotate save.php @ 1971:e62289760587

Bug #1349: PHP returns XML confirmation or error and message. Core responds. Bug #1449 not a bug
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Fri, 20 Nov 2015 15:39:01 +0000
parents 025867e74b01
children b448ed356355 888292c88c33
rev   line source
b@1478 1 <?php
b@1969 2 header('Access-Control-Allow-Origin: *');
nickjillings@1971 3 header("Content-type: text/xml");
b@1478 4 $postText = file_get_contents('php://input');
b@1478 5 $datetime = date('ymdHis');
b@1478 6 $xmlfile = "save".$datetime.".xml";
b@1478 7 $fileHandle = fopen("saves/".$xmlfile, 'w');
nickjillings@1971 8 if ($fileHandle == FALSE)
nickjillings@1971 9 {
nickjillings@1971 10 // Filehandle failed
nickjillings@1971 11 $xml = '<response state="error"><message>Could not open file</message></response>';
nickjillings@1971 12 echo $xml;
nickjillings@1971 13 return;
nickjillings@1971 14 }
nickjillings@1971 15 $wbytes = fwrite($fileHandle, $postText);
nickjillings@1971 16 if ($wbytes == FALSE)
nickjillings@1971 17 {
nickjillings@1971 18 // FileWrite failed
nickjillings@1971 19 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nickjillings@1971 20 echo $xml;
nickjillings@1971 21 return;
nickjillings@1971 22 }
b@1478 23 fclose($fileHandle);
nickjillings@1971 24
nickjillings@1971 25 // Return JSON confirmation data
nickjillings@1971 26 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nickjillings@1971 27 echo $xml;
b@1478 28 ?>