From bfdb952371793e5b46833e0ffc7beffe66828a94 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 19 Dec 2014 20:37:39 -0500 Subject: Update upload.php --- static/upload.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/static/upload.php b/static/upload.php index c05f7cd..686c8d9 100644 --- a/static/upload.php +++ b/static/upload.php @@ -30,16 +30,15 @@ function generate_name ($file) { // If we run out of tries, throw an exception. Should be caught and JSONified. if ($tries-- == 0) throw new Exception('Gave up trying to find an unused name'); - // TODO: come up with a better name generating algorithm, stop repeating myself. - // In case of autism change this to your likings and put it in a loop before - // putting it on a production server $newname = ''; // Filename Generator: - $newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter - $newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter - $newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter - $newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter - $newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter - $newname .= chr(mt_rand(ord("a"), ord("z"))); // + random lowercase letter + + // Reddit critizces, I fix. You're welcome. (http://www.reddit.com/r/shittyprogramming/comments/2ppsqk/url_generator/) + $startNumber = ord("a"); + $endNumber = ord("z"); + for ($i = 0; $i < 6; $i++) { + $newname .= chr(mt_rand($startNumber, $endNumber)); + } + // To add a dot or not after a file which has no extension if ($ext != '') $newname .= '.' . strip_tags($ext); -- cgit v1.2.3