Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'Overwrite Files' Checkbox to Give Users the Option of Overwriting Existing Files During Upload #1140

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tinyfilemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ function get_file_path () {
$chunkIndex = $_POST['dzchunkindex'];
$chunkTotal = $_POST['dztotalchunkcount'];
$fullPathInput = fm_clean_path($_REQUEST['fullpath']);
$overwrite_files = ($_REQUEST['overwrite_files'] ?? 'N');

$f = $_FILES;
$path = FM_ROOT_PATH;
Expand Down Expand Up @@ -1016,7 +1017,12 @@ function get_file_path () {
if ($chunkIndex == $chunkTotal - 1) {
if (file_exists ($fullPath)) {
$ext_1 = $ext ? '.'.$ext : '';
$fullPathTarget = $path . '/' . basename($fullPathInput, $ext_1) .'_'. date('ymdHis'). $ext_1;

if ($overwrite_files == 'Y') {
$fullPathTarget = $path . '/' . basename($fullPathInput, $ext_1) . $ext_1;
} else {
$fullPathTarget = $path . '/' . basename($fullPathInput, $ext_1) .'_'. date('ymdHis'). $ext_1;
}
} else {
$fullPathTarget = $fullPath;
}
Expand Down Expand Up @@ -1354,11 +1360,13 @@ function getUploadExt() {
<a href="?p=<?php echo FM_PATH ?>" class="float-right"><i class="fa fa-chevron-circle-left go-back"></i> <?php echo lng('Back')?></a>
<strong><?php echo lng('DestinationFolder') ?></strong>: <?php echo fm_enc(fm_convert_win(FM_PATH)) ?>
</p>
<p><label><input type="checkbox" name="overwrite_files" value="Y" onChange="document.getElementById('fileUploader').overwrite_files.value = (this.checked) ? this.value : '';">&nbsp;Overwrite existing files?</label></p>

<form action="<?php echo htmlspecialchars(FM_SELF_URL) . '?p=' . fm_enc(FM_PATH) ?>" class="dropzone card-tabs-container" id="fileUploader" enctype="multipart/form-data">
<input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
<input type="hidden" name="fullpath" id="fullpath" value="<?php echo fm_enc(FM_PATH) ?>">
<input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>">
<input type="hidden" name="overwrite_files" value="">
<div class="fallback">
<input name="file" type="file" multiple/>
</div>
Expand Down