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 | |
| parent | c7dd181df95ccab9c08818015f4abf27852ff4a0 (diff) | |
feat: preserve original filename option
Diffstat (limited to 'public')
| -rw-r--r-- | public/index.php | 30 | ||||
| -rw-r--r-- | public/static/style.css | 6 | ||||
| -rw-r--r-- | 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) { <textarea name="paste" placeholder="Enter your text here..."></textarea> </div> + <table class="vertical" id="form-upload-options"> + <tr> + <th>Preserve original filename:</th> + <td><input type="checkbox" name="preserve_original_name" value="1"></td> + </tr> + </table> <button type="submit">Upload</button> </form> </div> @@ -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 === '<?= $file['id'] ?>'); - console.log(file); if (file && file.urls && file.urls.deletion_url) { const buttons = document.getElementById('file-tab-buttons'); buttons.innerHTML = `<a href='${file.urls.deletion_url}'><button>Delete</button></a>` + buttons.innerHTML; @@ -296,6 +301,8 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) { </script> <?php else: ?> <script> + const formDetails = document.getElementById('form-upload-options'); + document.getElementById('form-text-upload').style.display = 'none'; let file = null; @@ -321,13 +328,13 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) { const fileURLWrapper = document.querySelector('#form-upload-wrapper>div'); fileURL.addEventListener('keyup', () => { fileUploadWrapper.style.display = fileURL.value.length == 0 ? 'block' : 'none'; - formSubmitButton.style.display = fileURL.value.length == 0 ? 'none' : 'block'; + setFormDetailsVisiblity(fileURL.value.length > 0); }); <?php endif; ?> const textArea = document.querySelector('#form-text-upload>textarea'); textArea.addEventListener('keyup', () => { - formSubmitButton.style.display = textArea.value.length == 0 ? 'none' : 'block'; + setFormDetailsVisiblity(fileURL.value.length > 0); }); const formSubmitButton = document.querySelector('#form-upload button[type=submit]'); @@ -338,7 +345,7 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) { file = e.target.files[0]; if (file) { fileUploadWrapper.innerHTML = `<h1>File: ${file.name}</h1>`; - formSubmitButton.style.display = 'block'; + setFormDetailsVisiblity(true); <?php if (FILEEXT_ENABLED): ?> fileURLWrapper.style.display = 'none'; <?php endif; ?> @@ -353,7 +360,7 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) { if (item.kind === "file") { file = item.getAsFile(); fileUploadWrapper.innerHTML = `<h1>File: ${file.name}</h1>`; - formSubmitButton.style.display = 'block'; + setFormDetailsVisiblity(true); <?php if (FILEEXT_ENABLED): ?> fileURLWrapper.style.display = 'none'; <?php endif; ?> @@ -381,10 +388,10 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) { }); - formSubmitButton.style.display = 'none'; + setFormDetailsVisiblity(false); if (textArea.value.length > 0) { - formSubmitButton.style.display = 'block'; + setFormDetailsVisiblity(true); showUploadType('text'); } @@ -413,7 +420,7 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) { fileURL.value = ''; <?php endif; ?> file = null; - formSubmitButton.style.display = 'none'; + setFormDetailsVisiblity(false); fetch(formUpload.getAttribute('action'), { 'body': form, @@ -452,6 +459,8 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) { let files = getUploadedFiles(); files.unshift(json.data); localStorage.setItem('uploaded_files', JSON.stringify(files)); + + formUpload.clear(); }); } @@ -552,6 +561,11 @@ if (FILE_CATALOG_FANCY_VIEW && $file_id) { } } } + + function setFormDetailsVisiblity(show) { + formDetails.style.display = show ? 'flex' : 'none'; + formSubmitButton.style.display = show ? 'block' : 'none'; + } </script> <?php endif; ?> 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'); } |
