annotate php/save.php @ 2538:464c6c6692d6

Beautified entire project.
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Mon, 14 Nov 2016 14:17:03 +0000
parents d26623bd65e0
children 7d2267e094ca
rev   line source
nicholas@2224 1 <?php
nicholas@2457 2 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
nicholas@2457 3 header("Cache-Control: post-check=0, pre-check=0", false);
nicholas@2457 4 header("Pragma: no-cache");
nicholas@2224 5 error_reporting(0);
giuliomoro@2337 6 $saveFilenamePrefix = isset($_GET['saveFilenamePrefix']) ? $_GET['saveFilenamePrefix'].'-' : '';
nicholas@2224 7 header('Access-Control-Allow-Origin: *');
nicholas@2224 8 header("Content-type: text/xml");
nicholas@2224 9 $postText = file_get_contents('php://input');
giuliomoro@2337 10 $file_key = $_GET['key'];
giuliomoro@2337 11 $filename = '../saves/'.$saveFilenamePrefix.'save-'.$file_key.".xml";
nicholas@2320 12 $doc = new DOMDocument;
nicholas@2320 13 $doc->preserveWhiteSpace = false;
nicholas@2320 14 $doc->formatOutput = true;
nicholas@2320 15 $doc->loadXML($postText);
nicholas@2320 16 $postText = $doc->saveXML();
nicholas@2224 17 $fileHandle = fopen($filename, 'w');
nicholas@2224 18 if ($fileHandle == FALSE)
nicholas@2224 19 {
nicholas@2224 20 // Filehandle failed
nicholas@2224 21 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@2224 22 echo $xml;
nicholas@2224 23 return;
nicholas@2224 24 }
nicholas@2224 25 $wbytes = fwrite($fileHandle, $postText);
nicholas@2224 26 if ($wbytes === FALSE)
nicholas@2224 27 {
nicholas@2224 28 // FileWrite failed
nicholas@2224 29 $xml = '<response state="error"><message>Could not write file "'.$filename.'"</message></response>';
nicholas@2224 30 echo $xml;
nicholas@2224 31 return;
nicholas@2224 32 }
nicholas@2224 33 fclose($fileHandle);
nicholas@2224 34
nicholas@2224 35 // Return XML confirmation data
nicholas@2224 36 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"'.$filename.'"</file></response>';
nicholas@2224 37 echo $xml;
nicholas@2538 38 ?>