annotate save.php @ 596:770ef730872b Dev_main

Hotfix: Confirmation on successful save.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Wed, 09 Mar 2016 14:40:12 +0000
parents 055f9763fada
children 0794fefefbd8
rev   line source
n@292 1 <?php
giuliomoro@583 2 error_reporting(0);
n@563 3 try{
n@563 4 date_default_timezone_get();
n@563 5 }
n@563 6 catch(Exception $e){
n@563 7 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini
n@563 8 }
b@343 9 header('Access-Control-Allow-Origin: *');
nicholas@345 10 header("Content-type: text/xml");
n@292 11 $postText = file_get_contents('php://input');
n@589 12 $file_key = $_GET['key'];
n@589 13 $filename = "saves/save-".$file_key.".xml";
n@589 14 $fileHandle = fopen($filename, 'w');
nicholas@345 15 if ($fileHandle == FALSE)
nicholas@345 16 {
nicholas@345 17 // Filehandle failed
nicholas@345 18 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@345 19 echo $xml;
nicholas@345 20 return;
nicholas@345 21 }
nicholas@345 22 $wbytes = fwrite($fileHandle, $postText);
giuliomoro@556 23 if ($wbytes === FALSE)
nicholas@345 24 {
nicholas@345 25 // FileWrite failed
nicholas@345 26 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nicholas@345 27 echo $xml;
nicholas@345 28 return;
nicholas@345 29 }
n@292 30 fclose($fileHandle);
nicholas@345 31
nicholas@345 32 // Return JSON confirmation data
nicholas@345 33 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nicholas@345 34 echo $xml;
giuliomoro@555 35 ?>