summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorMichael <wafflestealer654@users.noreply.github.com>2014-12-20 02:37:39 +0100
committerMichael <wafflestealer654@users.noreply.github.com>2014-12-20 02:37:39 +0100
commitbfdb952371793e5b46833e0ffc7beffe66828a94 (patch)
tree34322b83253e1e76d29634fe0ce9f00f8ee46562 /static
parentf629677d4cad993472a557464e54f177886fa03f (diff)
Update upload.php
Diffstat (limited to 'static')
-rw-r--r--static/upload.php17
1 files 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);