comparison save.php @ 824:cfe755cc2bc2

Feature #1456. PHP server adds a six character 'hash' to the end of the file.
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Mon, 23 Nov 2015 16:02:37 +0000
parents 7b0ce3a9ddc1
children 1b6fa37d46a4
comparison
equal deleted inserted replaced
823:a0d7a64d8325 824:cfe755cc2bc2
1 <?php 1 <?php
2 header('Access-Control-Allow-Origin: *'); 2 header('Access-Control-Allow-Origin: *');
3 header("Content-type: text/xml"); 3 header("Content-type: text/xml");
4 $postText = file_get_contents('php://input'); 4 $postText = file_get_contents('php://input');
5 $datetime = date('ymdHis'); 5 $datetime = date('ymdHis');
6 $xmlfile = "save".$datetime.".xml"; 6 $xmlfile = "save".$datetime."-".generateRandomString(6).".xml";
7 $fileHandle = fopen("saves/".$xmlfile, 'w'); 7 $fileHandle = fopen("saves/".$xmlfile, 'w');
8 if ($fileHandle == FALSE) 8 if ($fileHandle == FALSE)
9 { 9 {
10 // Filehandle failed 10 // Filehandle failed
11 $xml = '<response state="error"><message>Could not open file</message></response>'; 11 $xml = '<response state="error"><message>Could not open file</message></response>';
23 fclose($fileHandle); 23 fclose($fileHandle);
24 24
25 // Return JSON confirmation data 25 // Return JSON confirmation data
26 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>'; 26 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
27 echo $xml; 27 echo $xml;
28
29 // Random String generator from http://stackoverflow.com/questions/4356289/php-random-string-generator
30 function generateRandomString($length = 10) {
31 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
32 $charactersLength = strlen($characters);
33 $randomString = '';
34 for ($i = 0; $i < $length; $i++) {
35 $randomString .= $characters[rand(0, $charactersLength - 1)];
36 }
37 return $randomString;
38 }
28 ?> 39 ?>