Mercurial > hg > webaudioevaluationtool
diff save.php @ 357:9823ee8c823e Dev_main
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 | b448ed356355 |
children | a95d323a911e |
line wrap: on
line diff
--- a/save.php Thu Nov 26 09:59:22 2015 +0000 +++ b/save.php Fri Nov 27 09:27:33 2015 +0000 @@ -2,8 +2,9 @@ header('Access-Control-Allow-Origin: *'); header("Content-type: text/xml"); $postText = file_get_contents('php://input'); + $sha1_hash = sha1($postText); $datetime = date('ymdHis'); - $xmlfile = "save".$datetime."-".generateRandomString(6).".xml"; + $xmlfile = "save".$datetime."-".$sha1_hash.".xml"; $fileHandle = fopen("saves/".$xmlfile, 'w'); if ($fileHandle == FALSE) { @@ -25,15 +26,4 @@ // 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