annotate php/save.php @ 2402:6b6422523c88

Merge branch 'master' of https://github.com/BrechtDeMan/WebAudioEvaluationTool
author www-data <www-data@sucuk.dcs.qmul.ac.uk>
date Thu, 26 May 2016 17:20:50 +0100
parents d347dbab980d
children d26623bd65e0
rev   line source
nicholas@2224 1 <?php
nicholas@2224 2 error_reporting(0);
giuliomoro@2337 3 $saveFilenamePrefix = isset($_GET['saveFilenamePrefix']) ? $_GET['saveFilenamePrefix'].'-' : '';
nicholas@2224 4 header('Access-Control-Allow-Origin: *');
nicholas@2224 5 header("Content-type: text/xml");
nicholas@2224 6 $postText = file_get_contents('php://input');
giuliomoro@2337 7 $file_key = $_GET['key'];
giuliomoro@2337 8 $filename = '../saves/'.$saveFilenamePrefix.'save-'.$file_key.".xml";
nicholas@2320 9 $doc = new DOMDocument;
nicholas@2320 10 $doc->preserveWhiteSpace = false;
nicholas@2320 11 $doc->formatOutput = true;
nicholas@2320 12 $doc->loadXML($postText);
nicholas@2320 13 $postText = $doc->saveXML();
nicholas@2224 14 $fileHandle = fopen($filename, 'w');
nicholas@2224 15 if ($fileHandle == FALSE)
nicholas@2224 16 {
nicholas@2224 17 // Filehandle failed
nicholas@2224 18 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@2224 19 echo $xml;
nicholas@2224 20 return;
nicholas@2224 21 }
nicholas@2224 22 $wbytes = fwrite($fileHandle, $postText);
nicholas@2224 23 if ($wbytes === FALSE)
nicholas@2224 24 {
nicholas@2224 25 // FileWrite failed
nicholas@2224 26 $xml = '<response state="error"><message>Could not write file "'.$filename.'"</message></response>';
nicholas@2224 27 echo $xml;
nicholas@2224 28 return;
nicholas@2224 29 }
nicholas@2224 30 fclose($fileHandle);
nicholas@2224 31
nicholas@2224 32 // Return XML confirmation data
nicholas@2224 33 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"'.$filename.'"</file></response>';
nicholas@2224 34 echo $xml;
nicholas@2224 35 ?>