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