Mercurial > hg > webaudioevaluationtool
annotate php/save.php @ 2327:ced5aedb4cda
gitignore
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 03 May 2016 15:18:13 +0100 |
parents | ae69e61a6b76 |
children | d347dbab980d |
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@2320 | 8 $doc = new DOMDocument; |
nicholas@2320 | 9 $doc->preserveWhiteSpace = false; |
nicholas@2320 | 10 $doc->formatOutput = true; |
nicholas@2320 | 11 $doc->loadXML($postText); |
nicholas@2320 | 12 $postText = $doc->saveXML(); |
nicholas@2224 | 13 $fileHandle = fopen($filename, 'w'); |
nicholas@2224 | 14 if ($fileHandle == FALSE) |
nicholas@2224 | 15 { |
nicholas@2224 | 16 // Filehandle failed |
nicholas@2224 | 17 $xml = '<response state="error"><message>Could not open file</message></response>'; |
nicholas@2224 | 18 echo $xml; |
nicholas@2224 | 19 return; |
nicholas@2224 | 20 } |
nicholas@2224 | 21 $wbytes = fwrite($fileHandle, $postText); |
nicholas@2224 | 22 if ($wbytes === FALSE) |
nicholas@2224 | 23 { |
nicholas@2224 | 24 // FileWrite failed |
nicholas@2224 | 25 $xml = '<response state="error"><message>Could not write file "'.$filename.'"</message></response>'; |
nicholas@2224 | 26 echo $xml; |
nicholas@2224 | 27 return; |
nicholas@2224 | 28 } |
nicholas@2224 | 29 fclose($fileHandle); |
nicholas@2224 | 30 |
nicholas@2224 | 31 // Return XML confirmation data |
nicholas@2224 | 32 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"'.$filename.'"</file></response>'; |
nicholas@2224 | 33 echo $xml; |
nicholas@2224 | 34 ?> |