Mercurial > hg > waet-hammond-1
annotate new/php/save.php @ 22:1f375b7d75fd tip
updated warning for breaks during test
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 13 May 2016 19:01:08 +0100 |
parents | 01608b20a12d |
children |
rev | line source |
---|---|
giuliomoro@15 | 1 <?php |
giuliomoro@15 | 2 error_reporting(0); |
giuliomoro@16 | 3 $saveFilenamePrefix = isset($_GET['saveFilenamePrefix']) ? $_GET['saveFilenamePrefix'].'-' : ''; |
giuliomoro@15 | 4 header('Access-Control-Allow-Origin: *'); |
giuliomoro@15 | 5 header("Content-type: text/xml"); |
giuliomoro@15 | 6 $postText = file_get_contents('php://input'); |
giuliomoro@16 | 7 $file_key = $_GET['key']; |
giuliomoro@16 | 8 $filename = '../saves/'.$saveFilenamePrefix.'save-'.$file_key.".xml"; |
giuliomoro@15 | 9 $doc = new DOMDocument; |
giuliomoro@15 | 10 $doc->preserveWhiteSpace = false; |
giuliomoro@15 | 11 $doc->formatOutput = true; |
giuliomoro@15 | 12 $doc->loadXML($postText); |
giuliomoro@15 | 13 $postText = $doc->saveXML(); |
giuliomoro@15 | 14 $fileHandle = fopen($filename, 'w'); |
giuliomoro@15 | 15 if ($fileHandle == FALSE) |
giuliomoro@15 | 16 { |
giuliomoro@15 | 17 // Filehandle failed |
giuliomoro@15 | 18 $xml = '<response state="error"><message>Could not open file</message></response>'; |
giuliomoro@15 | 19 echo $xml; |
giuliomoro@15 | 20 return; |
giuliomoro@15 | 21 } |
giuliomoro@15 | 22 $wbytes = fwrite($fileHandle, $postText); |
giuliomoro@15 | 23 if ($wbytes === FALSE) |
giuliomoro@15 | 24 { |
giuliomoro@15 | 25 // FileWrite failed |
giuliomoro@15 | 26 $xml = '<response state="error"><message>Could not write file "'.$filename.'"</message></response>'; |
giuliomoro@15 | 27 echo $xml; |
giuliomoro@15 | 28 return; |
giuliomoro@15 | 29 } |
giuliomoro@15 | 30 fclose($fileHandle); |
giuliomoro@15 | 31 |
giuliomoro@15 | 32 // Return XML confirmation data |
giuliomoro@15 | 33 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"'.$filename.'"</file></response>'; |
giuliomoro@15 | 34 echo $xml; |
giuliomoro@16 | 35 ?> |