annotate save.php @ 562:3ddf4feceab7 Dev_main

Bug #1620: Defaults to Europe/London timezone.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Tue, 23 Feb 2016 16:57:06 +0000
parents 80796ff2ae66
children 27a96b51255c
rev   line source
n@292 1 <?php
n@562 2 date_default_timezone_set("Europe/London");
b@343 3 header('Access-Control-Allow-Origin: *');
nicholas@345 4 header("Content-type: text/xml");
giuliomoro@534 5 error_reporting(0);
n@292 6 $postText = file_get_contents('php://input');
nicholas@357 7 $sha1_hash = sha1($postText);
n@292 8 $datetime = date('ymdHis');
nicholas@357 9 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
n@292 10 $fileHandle = fopen("saves/".$xmlfile, 'w');
nicholas@345 11 if ($fileHandle == FALSE)
nicholas@345 12 {
nicholas@345 13 // Filehandle failed
nicholas@345 14 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@345 15 echo $xml;
nicholas@345 16 return;
nicholas@345 17 }
nicholas@345 18 $wbytes = fwrite($fileHandle, $postText);
giuliomoro@556 19 if ($wbytes === FALSE)
nicholas@345 20 {
nicholas@345 21 // FileWrite failed
nicholas@345 22 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nicholas@345 23 echo $xml;
nicholas@345 24 return;
nicholas@345 25 }
n@292 26 fclose($fileHandle);
nicholas@345 27
nicholas@345 28 // Return JSON confirmation data
nicholas@345 29 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nicholas@345 30 echo $xml;
giuliomoro@555 31 ?>