annotate save.php @ 1404:3b9f0bc523d6

test_create: Specification Node handles complete XML to DOM and DOM to XML conversions
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Fri, 04 Dec 2015 18:34:04 +0000
parents
children 2647dd909229 b5bf2f57187c 9ee921c8cdd3
rev   line source
nickjillings@1404 1 <?php
nickjillings@1404 2 header('Access-Control-Allow-Origin: *');
nickjillings@1404 3 header("Content-type: text/xml");
nickjillings@1404 4 $postText = file_get_contents('php://input');
nickjillings@1404 5 $sha1_hash = sha1($postText);
nickjillings@1404 6 $datetime = date('ymdHis');
nickjillings@1404 7 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
nickjillings@1404 8 $fileHandle = fopen("saves/".$xmlfile, 'w');
nickjillings@1404 9 if ($fileHandle == FALSE)
nickjillings@1404 10 {
nickjillings@1404 11 // Filehandle failed
nickjillings@1404 12 $xml = '<response state="error"><message>Could not open file</message></response>';
nickjillings@1404 13 echo $xml;
nickjillings@1404 14 return;
nickjillings@1404 15 }
nickjillings@1404 16 $wbytes = fwrite($fileHandle, $postText);
nickjillings@1404 17 if ($wbytes == FALSE)
nickjillings@1404 18 {
nickjillings@1404 19 // FileWrite failed
nickjillings@1404 20 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nickjillings@1404 21 echo $xml;
nickjillings@1404 22 return;
nickjillings@1404 23 }
nickjillings@1404 24 fclose($fileHandle);
nickjillings@1404 25
nickjillings@1404 26 // Return JSON confirmation data
nickjillings@1404 27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nickjillings@1404 28 echo $xml;
nickjillings@1404 29 ?>