Mercurial > hg > webaudioevaluationtool
annotate save.php @ 1195:b2d06aed8de1
Minor changes to instructions, demo page, and test examples
author | Brecht De Man <BrechtDeMan@users.noreply.github.com> |
---|---|
date | Fri, 19 Feb 2016 16:08:54 +0100 |
parents | 888292c88c33 |
children | 47bfd9594617 |
rev | line source |
---|---|
BrechtDeMan@715 | 1 <?php |
BrechtDeMan@746 | 2 header('Access-Control-Allow-Origin: *'); |
nicholas@748 | 3 header("Content-type: text/xml"); |
BrechtDeMan@715 | 4 $postText = file_get_contents('php://input'); |
nicholas@829 | 5 $sha1_hash = sha1($postText); |
BrechtDeMan@715 | 6 $datetime = date('ymdHis'); |
nicholas@829 | 7 $xmlfile = "save".$datetime."-".$sha1_hash.".xml"; |
BrechtDeMan@715 | 8 $fileHandle = fopen("saves/".$xmlfile, 'w'); |
nicholas@748 | 9 if ($fileHandle == FALSE) |
nicholas@748 | 10 { |
nicholas@748 | 11 // Filehandle failed |
nicholas@748 | 12 $xml = '<response state="error"><message>Could not open file</message></response>'; |
nicholas@748 | 13 echo $xml; |
nicholas@748 | 14 return; |
nicholas@748 | 15 } |
nicholas@748 | 16 $wbytes = fwrite($fileHandle, $postText); |
nicholas@748 | 17 if ($wbytes == FALSE) |
nicholas@748 | 18 { |
nicholas@748 | 19 // FileWrite failed |
nicholas@748 | 20 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>'; |
nicholas@748 | 21 echo $xml; |
nicholas@748 | 22 return; |
nicholas@748 | 23 } |
BrechtDeMan@715 | 24 fclose($fileHandle); |
nicholas@748 | 25 |
nicholas@748 | 26 // Return JSON confirmation data |
nicholas@748 | 27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>'; |
nicholas@748 | 28 echo $xml; |
BrechtDeMan@715 | 29 ?> |