annotate save.php @ 1220:585e06d319d2

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 5df87aa95395
children 310b4640b93d
rev   line source
BrechtDeMan@715 1 <?php
n@1220 2 date_default_timezone_set("Europe/London");
BrechtDeMan@746 3 header('Access-Control-Allow-Origin: *');
nicholas@748 4 header("Content-type: text/xml");
giuliomoro@1088 5 error_reporting(0);
BrechtDeMan@715 6 $postText = file_get_contents('php://input');
nicholas@829 7 $sha1_hash = sha1($postText);
BrechtDeMan@715 8 $datetime = date('ymdHis');
nicholas@829 9 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
BrechtDeMan@715 10 $fileHandle = fopen("saves/".$xmlfile, 'w');
nicholas@748 11 if ($fileHandle == FALSE)
nicholas@748 12 {
nicholas@748 13 // Filehandle failed
nicholas@748 14 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@748 15 echo $xml;
nicholas@748 16 return;
nicholas@748 17 }
nicholas@748 18 $wbytes = fwrite($fileHandle, $postText);
giuliomoro@1215 19 if ($wbytes === FALSE)
nicholas@748 20 {
nicholas@748 21 // FileWrite failed
nicholas@748 22 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nicholas@748 23 echo $xml;
nicholas@748 24 return;
nicholas@748 25 }
BrechtDeMan@715 26 fclose($fileHandle);
nicholas@748 27
nicholas@748 28 // Return JSON confirmation data
nicholas@748 29 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nicholas@748 30 echo $xml;
giuliomoro@1214 31 ?>