test_create: Specification Node handles complete XML to DOM and DOM to XML conversions
author |
Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
date |
Fri, 04 Dec 2015 18:34:04 +0000 |
parents |
|
children |
2647dd909229 b5bf2f57187c 9ee921c8cdd3 |
rev |
line source |
n@767
|
1 <?php
|
n@767
|
2 header('Access-Control-Allow-Origin: *');
|
n@767
|
3 header("Content-type: text/xml");
|
n@767
|
4 $postText = file_get_contents('php://input');
|
n@767
|
5 $sha1_hash = sha1($postText);
|
n@767
|
6 $datetime = date('ymdHis');
|
n@767
|
7 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
|
n@767
|
8 $fileHandle = fopen("saves/".$xmlfile, 'w');
|
n@767
|
9 if ($fileHandle == FALSE)
|
n@767
|
10 {
|
n@767
|
11 // Filehandle failed
|
n@767
|
12 $xml = '<response state="error"><message>Could not open file</message></response>';
|
n@767
|
13 echo $xml;
|
n@767
|
14 return;
|
n@767
|
15 }
|
n@767
|
16 $wbytes = fwrite($fileHandle, $postText);
|
n@767
|
17 if ($wbytes == FALSE)
|
n@767
|
18 {
|
n@767
|
19 // FileWrite failed
|
n@767
|
20 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
|
n@767
|
21 echo $xml;
|
n@767
|
22 return;
|
n@767
|
23 }
|
n@767
|
24 fclose($fileHandle);
|
n@767
|
25
|
n@767
|
26 // Return JSON confirmation data
|
n@767
|
27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
|
n@767
|
28 echo $xml;
|
n@767
|
29 ?> |