annotate save.php @ 1445:dd4fed6a03f2
On XML parser error, will clear the page to show only the error message.
author |
Nicholas Jillings <nickjillings@users.noreply.github.com> |
date |
Fri, 18 Dec 2015 18:33:08 +0000 |
parents |
1e85294554fe |
children |
2647dd909229 b5bf2f57187c 9ee921c8cdd3 |
rev |
line source |
b@1390
|
1 <?php
|
b@1390
|
2 header('Access-Control-Allow-Origin: *');
|
b@1390
|
3 header("Content-type: text/xml");
|
b@1390
|
4 $postText = file_get_contents('php://input');
|
b@1390
|
5 $sha1_hash = sha1($postText);
|
b@1390
|
6 $datetime = date('ymdHis');
|
b@1390
|
7 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
|
b@1390
|
8 $fileHandle = fopen("saves/".$xmlfile, 'w');
|
b@1390
|
9 if ($fileHandle == FALSE)
|
b@1390
|
10 {
|
b@1390
|
11 // Filehandle failed
|
b@1390
|
12 $xml = '<response state="error"><message>Could not open file</message></response>';
|
b@1390
|
13 echo $xml;
|
b@1390
|
14 return;
|
b@1390
|
15 }
|
b@1390
|
16 $wbytes = fwrite($fileHandle, $postText);
|
b@1390
|
17 if ($wbytes == FALSE)
|
b@1390
|
18 {
|
b@1390
|
19 // FileWrite failed
|
b@1390
|
20 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
|
b@1390
|
21 echo $xml;
|
b@1390
|
22 return;
|
b@1390
|
23 }
|
b@1390
|
24 fclose($fileHandle);
|
b@1390
|
25
|
b@1390
|
26 // Return JSON confirmation data
|
b@1390
|
27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
|
b@1390
|
28 echo $xml;
|
b@1390
|
29 ?> |