annotate save.php @ 2085:11328fe5d16d

Add DMRN Proposal
author Dave Moffat <me@davemoffat.com>
date Mon, 07 Dec 2015 11:21:01 +0000
parents 56bdd4d357f9
children 47bfd9594617
rev   line source
b@1478 1 <?php
b@1969 2 header('Access-Control-Allow-Origin: *');
nickjillings@1971 3 header("Content-type: text/xml");
b@1478 4 $postText = file_get_contents('php://input');
nickjillings@1466 5 $sha1_hash = sha1($postText);
b@1478 6 $datetime = date('ymdHis');
nickjillings@1466 7 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
b@1478 8 $fileHandle = fopen("saves/".$xmlfile, 'w');
nickjillings@1971 9 if ($fileHandle == FALSE)
nickjillings@1971 10 {
nickjillings@1971 11 // Filehandle failed
nickjillings@1971 12 $xml = '<response state="error"><message>Could not open file</message></response>';
nickjillings@1971 13 echo $xml;
nickjillings@1971 14 return;
nickjillings@1971 15 }
nickjillings@1971 16 $wbytes = fwrite($fileHandle, $postText);
nickjillings@1971 17 if ($wbytes == FALSE)
nickjillings@1971 18 {
nickjillings@1971 19 // FileWrite failed
nickjillings@1971 20 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nickjillings@1971 21 echo $xml;
nickjillings@1971 22 return;
nickjillings@1971 23 }
b@1478 24 fclose($fileHandle);
nickjillings@1971 25
nickjillings@1971 26 // Return JSON confirmation data
nickjillings@1971 27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nickjillings@1971 28 echo $xml;
b@1478 29 ?>