diff options
| author | ilotterytea <iltsu@alright.party> | 2025-06-06 23:33:22 +0400 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-06-06 23:33:22 +0400 |
| commit | 8f78f23399155d8cac347c22749484c784aa9ca0 (patch) | |
| tree | 12e137e8713ad571efadc6d426cddae9a69d7511 /public/upload.php | |
| parent | c7dd181df95ccab9c08818015f4abf27852ff4a0 (diff) | |
feat: preserve original filename option
Diffstat (limited to 'public/upload.php')
| -rw-r--r-- | public/upload.php | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/public/upload.php b/public/upload.php index 31822ba..bfe2113 100644 --- a/public/upload.php +++ b/public/upload.php @@ -15,6 +15,8 @@ if (!is_dir(FILE_UPLOAD_DIRECTORY) && !mkdir(FILE_UPLOAD_DIRECTORY, 0777, true)) } try { + $preserve_original_name = boolval($_POST['preserve_original_name'] ?? '0'); + $url = isset($_POST['url']) ? $_POST['url'] ?: null : null; $file = isset($_FILES['file']) ? $_FILES['file'] ?: null : null; if (empty($file['tmp_name'])) { @@ -194,6 +196,15 @@ try { $file_data['password'] = password_hash($file_data['password'], PASSWORD_DEFAULT); $file_data['views'] = 0; $file_data['uploaded_at'] = time(); + + if ($preserve_original_name) { + if ($file && !empty($file['name'])) { + $file_data['original_name'] = $file['name']; + } else if ($url) { + $file_data['original_name'] = $url; + } + } + if (!is_dir(FILE_METADATA_DIRECTORY) && !mkdir(FILE_METADATA_DIRECTORY, 0777, true)) { throw new RuntimeException('Failed to create a folder for file metadata'); } |
