summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Johansson (neku) <neku@pomf.se>2014-12-20 03:01:50 +0100
committerEric Johansson (neku) <neku@pomf.se>2014-12-20 03:01:50 +0100
commit6a3a495457940b702341426d9c2d922a60dc072e (patch)
tree34322b83253e1e76d29634fe0ce9f00f8ee46562
parentf629677d4cad993472a557464e54f177886fa03f (diff)
parentbfdb952371793e5b46833e0ffc7beffe66828a94 (diff)
Merge pull request #24 from wafflestealer654/patch-1
Update upload.php
-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);