Mercurial > hg > webaudioevaluationtool
annotate php/save.php @ 2224:760719986df3
Tidy up file locations.
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Thu, 14 Apr 2016 13:54:24 +0100 |
parents | |
children | ae69e61a6b76 |
rev | line source |
---|---|
nicholas@2224 | 1 <?php |
nicholas@2224 | 2 error_reporting(0); |
nicholas@2224 | 3 header('Access-Control-Allow-Origin: *'); |
nicholas@2224 | 4 header("Content-type: text/xml"); |
nicholas@2224 | 5 $postText = file_get_contents('php://input'); |
nicholas@2224 | 6 $file_key = $_GET['key']; |
nicholas@2224 | 7 $filename = "../saves/save-".$file_key.".xml"; |
nicholas@2224 | 8 $fileHandle = fopen($filename, 'w'); |
nicholas@2224 | 9 if ($fileHandle == FALSE) |
nicholas@2224 | 10 { |
nicholas@2224 | 11 // Filehandle failed |
nicholas@2224 | 12 $xml = '<response state="error"><message>Could not open file</message></response>'; |
nicholas@2224 | 13 echo $xml; |
nicholas@2224 | 14 return; |
nicholas@2224 | 15 } |
nicholas@2224 | 16 $wbytes = fwrite($fileHandle, $postText); |
nicholas@2224 | 17 if ($wbytes === FALSE) |
nicholas@2224 | 18 { |
nicholas@2224 | 19 // FileWrite failed |
nicholas@2224 | 20 $xml = '<response state="error"><message>Could not write file "'.$filename.'"</message></response>'; |
nicholas@2224 | 21 echo $xml; |
nicholas@2224 | 22 return; |
nicholas@2224 | 23 } |
nicholas@2224 | 24 fclose($fileHandle); |
nicholas@2224 | 25 |
nicholas@2224 | 26 // Return XML confirmation data |
nicholas@2224 | 27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"'.$filename.'"</file></response>'; |
nicholas@2224 | 28 echo $xml; |
nicholas@2224 | 29 ?> |