annotate save.php @ 1099:0a15fa67bda1

First draft of AES poster
author Dave <djmoffat@users.noreply.github.com>
date Tue, 23 Feb 2016 15:19:31 +0000
parents
children 2647dd909229 b5bf2f57187c 9ee921c8cdd3
rev   line source
djmoffat@1099 1 <?php
djmoffat@1099 2 header('Access-Control-Allow-Origin: *');
djmoffat@1099 3 header("Content-type: text/xml");
djmoffat@1099 4 $postText = file_get_contents('php://input');
djmoffat@1099 5 $sha1_hash = sha1($postText);
djmoffat@1099 6 $datetime = date('ymdHis');
djmoffat@1099 7 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
djmoffat@1099 8 $fileHandle = fopen("saves/".$xmlfile, 'w');
djmoffat@1099 9 if ($fileHandle == FALSE)
djmoffat@1099 10 {
djmoffat@1099 11 // Filehandle failed
djmoffat@1099 12 $xml = '<response state="error"><message>Could not open file</message></response>';
djmoffat@1099 13 echo $xml;
djmoffat@1099 14 return;
djmoffat@1099 15 }
djmoffat@1099 16 $wbytes = fwrite($fileHandle, $postText);
djmoffat@1099 17 if ($wbytes == FALSE)
djmoffat@1099 18 {
djmoffat@1099 19 // FileWrite failed
djmoffat@1099 20 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
djmoffat@1099 21 echo $xml;
djmoffat@1099 22 return;
djmoffat@1099 23 }
djmoffat@1099 24 fclose($fileHandle);
djmoffat@1099 25
djmoffat@1099 26 // Return JSON confirmation data
djmoffat@1099 27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
djmoffat@1099 28 echo $xml;
djmoffat@1099 29 ?>