diff options
| author | Eric Johansson (neku) <neku@pomf.se> | 2014-12-20 03:01:50 +0100 |
|---|---|---|
| committer | Eric Johansson (neku) <neku@pomf.se> | 2014-12-20 03:01:50 +0100 |
| commit | 6a3a495457940b702341426d9c2d922a60dc072e (patch) | |
| tree | 34322b83253e1e76d29634fe0ce9f00f8ee46562 /static/upload.php | |
| parent | f629677d4cad993472a557464e54f177886fa03f (diff) | |
| parent | bfdb952371793e5b46833e0ffc7beffe66828a94 (diff) | |
Merge pull request #24 from wafflestealer654/patch-1
Update upload.php
Diffstat (limited to 'static/upload.php')
| -rw-r--r-- | static/upload.php | 17 |
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); |
