Mercurial > hg > webaudioevaluationtool
annotate save.php @ 748:b9785aaab2a4
Bug #1349: PHP returns XML confirmation or error and message. Core responds. Bug #1449 not a bug
author | Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk> |
---|---|
date | Fri, 20 Nov 2015 15:39:01 +0000 |
parents | c64529e5dee4 |
children | b448ed356355 888292c88c33 |
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'); |
BrechtDeMan@715 | 5 $datetime = date('ymdHis'); |
BrechtDeMan@715 | 6 $xmlfile = "save".$datetime.".xml"; |
BrechtDeMan@715 | 7 $fileHandle = fopen("saves/".$xmlfile, 'w'); |
nicholas@748 | 8 if ($fileHandle == FALSE) |
nicholas@748 | 9 { |
nicholas@748 | 10 // Filehandle failed |
nicholas@748 | 11 $xml = '<response state="error"><message>Could not open file</message></response>'; |
nicholas@748 | 12 echo $xml; |
nicholas@748 | 13 return; |
nicholas@748 | 14 } |
nicholas@748 | 15 $wbytes = fwrite($fileHandle, $postText); |
nicholas@748 | 16 if ($wbytes == FALSE) |
nicholas@748 | 17 { |
nicholas@748 | 18 // FileWrite failed |
nicholas@748 | 19 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>'; |
nicholas@748 | 20 echo $xml; |
nicholas@748 | 21 return; |
nicholas@748 | 22 } |
BrechtDeMan@715 | 23 fclose($fileHandle); |
nicholas@748 | 24 |
nicholas@748 | 25 // Return JSON confirmation data |
nicholas@748 | 26 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>'; |
nicholas@748 | 27 echo $xml; |
BrechtDeMan@715 | 28 ?> |