annotate save.php @ 1092:e4b378468589

Merge
author Brecht De Man <BrechtDeMan@users.noreply.github.com>
date Thu, 10 Mar 2016 10:38:31 +0100
parents c07b9e2312ba
children f4f9cde581aa
rev   line source
n@1090 1 <?php
n@1090 2 error_reporting(0);
n@1090 3 try{
n@1090 4 date_default_timezone_get();
n@1090 5 }
n@1090 6 catch(Exception $e){
n@1090 7 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini
n@1090 8 }
n@1090 9 header('Access-Control-Allow-Origin: *');
n@1090 10 header("Content-type: text/xml");
n@1090 11 $postText = file_get_contents('php://input');
n@1090 12 $file_key = $_GET['key'];
n@1090 13 $filename = "saves/save-".$file_key.".xml";
n@1090 14 $fileHandle = fopen($filename, 'w');
n@1090 15 if ($fileHandle == FALSE)
n@1090 16 {
n@1090 17 // Filehandle failed
n@1090 18 $xml = '<response state="error"><message>Could not open file</message></response>';
n@1090 19 echo $xml;
n@1090 20 return;
n@1090 21 }
n@1090 22 $wbytes = fwrite($fileHandle, $postText);
n@1090 23 if ($wbytes === FALSE)
n@1090 24 {
n@1090 25 // FileWrite failed
n@1090 26 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
n@1090 27 echo $xml;
n@1090 28 return;
n@1090 29 }
n@1090 30 fclose($fileHandle);
n@1090 31
n@1090 32 // Return JSON confirmation data
n@1090 33 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
n@1090 34 echo $xml;
n@1090 35 ?>