changeset 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 a0d7a64d8325
children 8fb8f3c1acf8
files save.php
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/save.php	Mon Nov 23 15:48:07 2015 +0000
+++ b/save.php	Mon Nov 23 16:02:37 2015 +0000
@@ -3,7 +3,7 @@
 	header("Content-type: text/xml");
 	$postText = file_get_contents('php://input');
 	$datetime = date('ymdHis');
-	$xmlfile = "save".$datetime.".xml";
+	$xmlfile = "save".$datetime."-".generateRandomString(6).".xml";
 	$fileHandle = fopen("saves/".$xmlfile, 'w');
 	if ($fileHandle == FALSE)
 	{
@@ -25,4 +25,15 @@
 	// Return JSON confirmation data
 	$xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
 	echo $xml;
+	
+	// Random String generator from http://stackoverflow.com/questions/4356289/php-random-string-generator
+	function generateRandomString($length = 10) {
+    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+    $charactersLength = strlen($characters);
+    $randomString = '';
+    for ($i = 0; $i < $length; $i++) {
+        $randomString .= $characters[rand(0, $charactersLength - 1)];
+    }
+    return $randomString;
+}
 ?>
\ No newline at end of file