annotate save.php @ 563:27a96b51255c Dev_main

Better solve for #1629
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Tue, 23 Feb 2016 16:59:59 +0000
parents 3ddf4feceab7
children 6833d8c2b52e
rev   line source
n@292 1 <?php
n@563 2 try{
n@563 3 date_default_timezone_get();
n@563 4 }
n@563 5 catch(Exception $e){
n@563 6 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini
n@563 7 }
b@343 8 header('Access-Control-Allow-Origin: *');
nicholas@345 9 header("Content-type: text/xml");
giuliomoro@534 10 error_reporting(0);
n@292 11 $postText = file_get_contents('php://input');
nicholas@357 12 $sha1_hash = sha1($postText);
n@292 13 $datetime = date('ymdHis');
nicholas@357 14 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
n@292 15 $fileHandle = fopen("saves/".$xmlfile, 'w');
nicholas@345 16 if ($fileHandle == FALSE)
nicholas@345 17 {
nicholas@345 18 // Filehandle failed
nicholas@345 19 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@345 20 echo $xml;
nicholas@345 21 return;
nicholas@345 22 }
nicholas@345 23 $wbytes = fwrite($fileHandle, $postText);
giuliomoro@556 24 if ($wbytes === FALSE)
nicholas@345 25 {
nicholas@345 26 // FileWrite failed
nicholas@345 27 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nicholas@345 28 echo $xml;
nicholas@345 29 return;
nicholas@345 30 }
n@292 31 fclose($fileHandle);
nicholas@345 32
nicholas@345 33 // Return JSON confirmation data
nicholas@345 34 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nicholas@345 35 echo $xml;
giuliomoro@555 36 ?>