annotate save.php @ 1940:fffc644a018d

Hotfix: Updated schema. <audioelement>, <surveyelement> and <commentquestion> have optional name attribute.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Wed, 09 Mar 2016 11:29:16 +0000
parents 7c846e19725f
children 83b439322229
rev   line source
me@1936 1 <?php
nickjillings@1939 2 error_reporting(0);
nickjillings@1939 3 try{
nickjillings@1939 4 date_default_timezone_get();
nickjillings@1939 5 }
nickjillings@1939 6 catch(Exception $e){
nickjillings@1939 7 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini
nickjillings@1939 8 }
me@1936 9 header('Access-Control-Allow-Origin: *');
me@1936 10 header("Content-type: text/xml");
me@1936 11 $postText = file_get_contents('php://input');
me@1936 12 $sha1_hash = sha1($postText);
me@1936 13 $datetime = date('ymdHis');
me@1936 14 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
me@1936 15 $fileHandle = fopen("saves/".$xmlfile, 'w');
me@1936 16 if ($fileHandle == FALSE)
me@1936 17 {
me@1936 18 // Filehandle failed
me@1936 19 $xml = '<response state="error"><message>Could not open file</message></response>';
me@1936 20 echo $xml;
me@1936 21 return;
me@1936 22 }
me@1936 23 $wbytes = fwrite($fileHandle, $postText);
nickjillings@1939 24 if ($wbytes === FALSE)
me@1936 25 {
me@1936 26 // FileWrite failed
me@1936 27 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
me@1936 28 echo $xml;
me@1936 29 return;
me@1936 30 }
me@1936 31 fclose($fileHandle);
me@1936 32
me@1936 33 // Return JSON confirmation data
me@1936 34 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
me@1936 35 echo $xml;
nickjillings@1939 36 ?>