From 8f78f23399155d8cac347c22749484c784aa9ca0 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Fri, 6 Jun 2025 23:33:22 +0400 Subject: feat: preserve original filename option --- public/index.php | 30 ++++++++++++++++++++++-------- public/static/style.css | 6 +++++- public/upload.php | 11 +++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/public/index.php b/public/index.php index 5fefb0f..6232508 100644 --- a/public/index.php +++ b/public/index.php @@ -265,6 +265,12 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) { + + + + + +
Preserve original filename:
@@ -288,7 +294,6 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) { // adding deletion button const files = JSON.parse(localStorage.getItem('uploaded_files') ?? '[]'); const file = files.find((x) => x.id === ''); - console.log(file); if (file && file.urls && file.urls.deletion_url) { const buttons = document.getElementById('file-tab-buttons'); buttons.innerHTML = `` + buttons.innerHTML; @@ -296,6 +301,8 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) { diff --git a/public/static/style.css b/public/static/style.css index e76b7c6..3edf252 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -66,10 +66,14 @@ table.vertical { } table.vertical th { - text-align: end; + text-align: right; vertical-align: top; } +table.vertical.left th { + text-align: left; +} + /** FORM */ button[type=submit] { background: linear-gradient(0deg, var(--box-tab-background), var(--background)); 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'); } -- cgit v1.2.3