comparison save.php @ 820:7b0ce3a9ddc1

Merge from branch "WAC2016"
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Mon, 23 Nov 2015 09:13:12 +0000
parents 9c579fc05a09
children cfe755cc2bc2
comparison
equal deleted inserted replaced
819:bf38bba18886 820:7b0ce3a9ddc1
1 <?php 1 <?php
2 head('Access-Control-Allow-Origin: *'); 2 header('Access-Control-Allow-Origin: *');
3 header("Content-type: text/xml");
3 $postText = file_get_contents('php://input'); 4 $postText = file_get_contents('php://input');
4 $datetime = date('ymdHis'); 5 $datetime = date('ymdHis');
5 $xmlfile = "save".$datetime.".xml"; 6 $xmlfile = "save".$datetime.".xml";
6 $fileHandle = fopen("saves/".$xmlfile, 'w'); 7 $fileHandle = fopen("saves/".$xmlfile, 'w');
7 fwrite($fileHandle, $postText); 8 if ($fileHandle == FALSE)
9 {
10 // Filehandle failed
11 $xml = '<response state="error"><message>Could not open file</message></response>';
12 echo $xml;
13 return;
14 }
15 $wbytes = fwrite($fileHandle, $postText);
16 if ($wbytes == FALSE)
17 {
18 // FileWrite failed
19 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
20 echo $xml;
21 return;
22 }
8 fclose($fileHandle); 23 fclose($fileHandle);
24
25 // Return JSON confirmation data
26 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
27 echo $xml;
9 ?> 28 ?>