Mercurial > hg > webaudioevaluationtool
annotate save.php @ 1289:175cf75946f7
Merge
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Wed, 09 Mar 2016 14:36:47 +0000 |
parents | |
children | f4f9cde581aa |
rev | line source |
---|---|
nickjillings@1289 | 1 <?php |
nickjillings@1289 | 2 error_reporting(0); |
nickjillings@1289 | 3 try{ |
nickjillings@1289 | 4 date_default_timezone_get(); |
nickjillings@1289 | 5 } |
nickjillings@1289 | 6 catch(Exception $e){ |
nickjillings@1289 | 7 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini |
nickjillings@1289 | 8 } |
nickjillings@1289 | 9 header('Access-Control-Allow-Origin: *'); |
nickjillings@1289 | 10 header("Content-type: text/xml"); |
nickjillings@1289 | 11 $postText = file_get_contents('php://input'); |
nickjillings@1289 | 12 $file_key = $_GET['key']; |
nickjillings@1289 | 13 $filename = "saves/save-".$file_key.".xml"; |
nickjillings@1289 | 14 $fileHandle = fopen($filename, 'w'); |
nickjillings@1289 | 15 if ($fileHandle == FALSE) |
nickjillings@1289 | 16 { |
nickjillings@1289 | 17 // Filehandle failed |
nickjillings@1289 | 18 $xml = '<response state="error"><message>Could not open file</message></response>'; |
nickjillings@1289 | 19 echo $xml; |
nickjillings@1289 | 20 return; |
nickjillings@1289 | 21 } |
nickjillings@1289 | 22 $wbytes = fwrite($fileHandle, $postText); |
nickjillings@1289 | 23 if ($wbytes === FALSE) |
nickjillings@1289 | 24 { |
nickjillings@1289 | 25 // FileWrite failed |
nickjillings@1289 | 26 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>'; |
nickjillings@1289 | 27 echo $xml; |
nickjillings@1289 | 28 return; |
nickjillings@1289 | 29 } |
nickjillings@1289 | 30 fclose($fileHandle); |
nickjillings@1289 | 31 |
nickjillings@1289 | 32 // Return JSON confirmation data |
nickjillings@1289 | 33 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>'; |
nickjillings@1289 | 34 echo $xml; |
nickjillings@1289 | 35 ?> |