annotate save.php @ 1102:b5bf2f57187c

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