annotate save.php @ 1936:94e57a566167

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