diff options
| author | ilotterytea <iltsu@alright.party> | 2025-06-02 01:21:20 +0400 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-06-02 01:21:20 +0400 |
| commit | 352ad8ee0ec3ecb676eda574331f8674e93f391d (patch) | |
| tree | 77871c1c226be615494fd5838579d1c39843bf3c /public/upload.php | |
| parent | 2c686a312c3d0a61fe1666a1318c2c4d36535470 (diff) | |
feat: check for existing file ids
Diffstat (limited to 'public/upload.php')
| -rw-r--r-- | public/upload.php | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/public/upload.php b/public/upload.php index 705f32b..3b7f58a 100644 --- a/public/upload.php +++ b/public/upload.php @@ -94,7 +94,16 @@ try { throw new RuntimeException('No URL or file specified'); } - $file_id = FILE_ID_PREFIX . generate_random_char_sequence(FILE_ID_CHARACTERS, FILE_ID_LENGTH); + $file_id_length = FILE_ID_LENGTH; + $file_id_gen_attempts = 0; + do { + $file_id = FILE_ID_PREFIX . generate_random_char_sequence(FILE_ID_CHARACTERS, $file_id_length); + if ($file_id_gen_attempts > 20) { + $file_id_length++; + $file_id_gen_attempts = 0; + } + $file_id_gen_attempts++; + } while (is_file(FILE_UPLOAD_DIRECTORY . "/{$file_id}.{$file_data['extension']}")); $file_data['id'] = $file_id; if (isset($url)) { |
