From 626a227f76154b8e6e08c4c128d87bf6b4dc1a93 Mon Sep 17 00:00:00 2001 From: Rj48 Date: Sun, 22 Jan 2017 17:17:15 +0100 Subject: [PATCH] prevent filename collisions --- index.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 6cf9eee..30c7068 100755 --- a/index.php +++ b/index.php @@ -112,9 +112,14 @@ function storeFile($name, $tmpFile, $formatted = false) } $ext = getExtension($name); - $id = rndStr($ID_LENGTH); - $basename = $id . '.' . $ext; - $target_file = $STORE_PATH . $basename; + $len = $ID_LENGTH; + do //generate filenames until we get one, that doesn't already exist + { + $id = rndStr($len++); + $basename = $id . '.' . $ext; + $target_file = $STORE_PATH . $basename; + } while (file_exists($target_file)); + $res = move_uploaded_file($tmpFile, $target_file); if ($res) {