annotate save.php @ 1350:b6389ceaeaa5

Confirmed working (using examples) on OSX (Chrome/Safari/Firefox)
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Thu, 14 Jan 2016 16:00:52 +0000
parents 64541cd9265d
children 2647dd909229 b5bf2f57187c 9ee921c8cdd3
rev   line source
nickjillings@1318 1 <?php
nickjillings@1318 2 header('Access-Control-Allow-Origin: *');
nickjillings@1318 3 header("Content-type: text/xml");
nickjillings@1318 4 $postText = file_get_contents('php://input');
nickjillings@1318 5 $sha1_hash = sha1($postText);
nickjillings@1318 6 $datetime = date('ymdHis');
nickjillings@1318 7 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
nickjillings@1318 8 $fileHandle = fopen("saves/".$xmlfile, 'w');
nickjillings@1318 9 if ($fileHandle == FALSE)
nickjillings@1318 10 {
nickjillings@1318 11 // Filehandle failed
nickjillings@1318 12 $xml = '<response state="error"><message>Could not open file</message></response>';
nickjillings@1318 13 echo $xml;
nickjillings@1318 14 return;
nickjillings@1318 15 }
nickjillings@1318 16 $wbytes = fwrite($fileHandle, $postText);
nickjillings@1318 17 if ($wbytes == FALSE)
nickjillings@1318 18 {
nickjillings@1318 19 // FileWrite failed
nickjillings@1318 20 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nickjillings@1318 21 echo $xml;
nickjillings@1318 22 return;
nickjillings@1318 23 }
nickjillings@1318 24 fclose($fileHandle);
nickjillings@1318 25
nickjillings@1318 26 // Return JSON confirmation data
nickjillings@1318 27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nickjillings@1318 28 echo $xml;
nickjillings@1318 29 ?>