diff options
| -rw-r--r-- | static/includes/settings.inc.php | 4 | ||||
| -rw-r--r-- | static/upload.php | 12 |
2 files changed, 9 insertions, 7 deletions
diff --git a/static/includes/settings.inc.php b/static/includes/settings.inc.php index e909b9a..9751cff 100644 --- a/static/includes/settings.inc.php +++ b/static/includes/settings.inc.php @@ -9,8 +9,10 @@ define('POMF_DB_PASS', '***'); // Root location of files define('POMF_FILES_ROOT', '/mnt/pantsu/http/files/'); -// Maximum number of iterations while generating a new name +// Maximum number of iterations while generating a new filename define('POMF_FILES_RETRIES', 15); +// Number of random characters to use in a new filename +define('POMF_FILES_LENGTH', 6); // URL to prepend to output (include trailing slash) define('POMF_URL', 'https://i.pantsu.cat/'); diff --git a/static/upload.php b/static/upload.php index 8aac02c..6e54ae1 100644 --- a/static/upload.php +++ b/static/upload.php @@ -23,8 +23,9 @@ function generate_name ($file) { global $doubledots; // We start at N retries, and --N until we give up - $tries = POMF_FILES_RETRIES; - $ext = pathinfo($file->name, PATHINFO_EXTENSION); + $tries = POMF_FILES_RETRIES; + $length = POMF_FILES_LENGTH; + $ext = pathinfo($file->name, PATHINFO_EXTENSION); // Check if extension is a double-dot extension and, if true, override $ext $revname = strrev($file->name); @@ -39,11 +40,10 @@ function generate_name ($file) { // Iterate until we reach the maximum number of retries if ($tries-- == 0) throw new Exception('Gave up trying to find an unused name', 500); - $chars = 'abcdefghijklmnopqrstuvwxyz'; + $chars = range('a', 'z'); $name = ''; - for ($i = 0; $i < 6; $i++) { - $name .= $chars[mt_rand(0, 25)]; - // $chars string length is hardcoded, should use a variable to store it? + for ($i = 0; $i < $length; $i++) { + $name .= $chars[array_rand($chars)]; } // Add the extension to the file name |
