annotate save.php @ 829:75e1c1ce6604

Bug #1464 #1456, PHP server hashes file contents to differentiate file names. Confirmed working on multiple connections with same file contents.
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Fri, 27 Nov 2015 09:27:33 +0000
parents 1b6fa37d46a4
children 2647dd909229
rev   line source
n@816 1 <?php
n@820 2 header('Access-Control-Allow-Origin: *');
n@820 3 header("Content-type: text/xml");
n@816 4 $postText = file_get_contents('php://input');
nicholas@829 5 $sha1_hash = sha1($postText);
n@816 6 $datetime = date('ymdHis');
nicholas@829 7 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
n@816 8 $fileHandle = fopen("saves/".$xmlfile, 'w');
n@820 9 if ($fileHandle == FALSE)
n@820 10 {
n@820 11 // Filehandle failed
n@820 12 $xml = '<response state="error"><message>Could not open file</message></response>';
n@820 13 echo $xml;
n@820 14 return;
n@820 15 }
n@820 16 $wbytes = fwrite($fileHandle, $postText);
n@820 17 if ($wbytes == FALSE)
n@820 18 {
n@820 19 // FileWrite failed
n@820 20 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
n@820 21 echo $xml;
n@820 22 return;
n@820 23 }
n@816 24 fclose($fileHandle);
n@820 25
n@820 26 // Return JSON confirmation data
n@820 27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
n@820 28 echo $xml;
n@816 29 ?>