annotate save.php @ 1890:1d0936cfa1d4

Merge
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Thu, 10 Mar 2016 17:08:10 +0000
parents a6cfd378891c 49d06c3dc44e
children
rev   line source
b@1478 1 <?php
giuliomoro@1879 2 error_reporting(0);
b@1508 3 header('Access-Control-Allow-Origin: *');
nickjillings@1510 4 header("Content-type: text/xml");
b@1478 5 $postText = file_get_contents('php://input');
nickjillings@1883 6 $file_key = $_GET['key'];
nickjillings@1883 7 $filename = "saves/save-".$file_key.".xml";
nickjillings@1883 8 $fileHandle = fopen($filename, 'w');
nickjillings@1510 9 if ($fileHandle == FALSE)
nickjillings@1510 10 {
nickjillings@1510 11 // Filehandle failed
nickjillings@1510 12 $xml = '<response state="error"><message>Could not open file</message></response>';
nickjillings@1510 13 echo $xml;
nickjillings@1510 14 return;
nickjillings@1510 15 }
nickjillings@1510 16 $wbytes = fwrite($fileHandle, $postText);
giuliomoro@1856 17 if ($wbytes === FALSE)
nickjillings@1510 18 {
nickjillings@1510 19 // FileWrite failed
nickjillings@1292 20 $xml = '<response state="error"><message>Could not write file "'.$filename.'"</message></response>';
nickjillings@1510 21 echo $xml;
nickjillings@1510 22 return;
nickjillings@1510 23 }
b@1478 24 fclose($fileHandle);
nickjillings@1510 25
nickjillings@1292 26 // Return XML confirmation data
nickjillings@1292 27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"'.$filename.'"</file></response>';
nickjillings@1510 28 echo $xml;
nickjillings@1292 29 ?>