Fix multiple download and browse while downloading#1242
Merged
prasathmani merged 1 commit intoprasathmani:masterfrom Oct 14, 2024
Merged
Conversation
prasathmani
approved these changes
Oct 14, 2024
ner00
reviewed
Oct 14, 2024
| <li class="list-inline-item"> <a href="#/select-all" class="btn btn-small btn-outline-primary btn-2" onclick="select_all();return false;"><i class="fa fa-check-square"></i> <?php echo lng('SelectAll') ?> </a></li> | ||
| <li class="list-inline-item"><a href="#/unselect-all" class="btn btn-small btn-outline-primary btn-2" onclick="unselect_all();return false;"><i class="fa fa-window-close"></i> <?php echo lng('UnSelectAll') ?> </a></li> | ||
| <li class="list-inline-item"><a href="#/invert-all" class="btn btn-small btn-outline-primary btn-2" onclick="invert_all();return false;"><i class="fa fa-th-list"></i> <?php echo lng('InvertSelection') ?> </a></li> | ||
| <li class="list-inline-item"><input type="submit" class="hidden" name="download" id="a-download" value="Download" onclick="return confirm('<?php echo lng('Download selected files and folders?'); ?>')"> |
Contributor
There was a problem hiding this comment.
Download selected files and folders?
Does it work for folders though?
ner00
reviewed
Oct 14, 2024
| // Add the file to the ZIP archive | ||
| $zip->addFile($new_path, basename($new_path)); | ||
| } else { | ||
| $errors++; |
Contributor
There was a problem hiding this comment.
It clearly does not work with folders, so prompting Download selected files and folders? is misleading.
Contributor
There was a problem hiding this comment.
I think here is a good opportunity to make good use of the included FM_Zipper class.
Just a suggestion, but this would work okay:
// Mass downloading
if (isset($_POST['group'], $_POST['download'], $_POST['token']) && !FM_READONLY) {
// Verify token to ensure it's valid
if(!verifyToken($_POST['token'])) {
fm_set_msg(lng("Invalid Token."), 'error');
exit;
}
$path = FM_ROOT_PATH;
if (FM_PATH != '') {
$path .= '/' . FM_PATH;
}
$files = $_POST['file']; // List of selected files
if (is_array($files) && count($files)) {
// Create a new ZIP archive
$zip = new FM_Zipper();
$zip_filename = 'download_' . date('Y-m-d_H-i-s') . '.zip';
$zip_filepath = sys_get_temp_dir() . '/' . $zip_filename;
chdir($path);
$sanitized_filepaths = array();
foreach($files as $f){
if ($f != '') {
array_push($sanitized_filepaths, fm_clean_path($f)); // Sanitize the file path
}
}
$res = $zip->create($zip_filepath, $sanitized_filepaths);
if ($res && file_exists($zip_filepath)) {
// Serve the ZIP file for download
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . $zip_filename . '"');
header('Content-Length: ' . filesize($zip_filepath));
readfile($zip_filepath);
// Remove the ZIP file from the temporary directory after download
unlink($zip_filepath);
exit;
} else {
fm_set_msg(lng('Error creating ZIP file'), 'error');
}
} else {
fm_set_msg(lng('Nothing selected'), 'alert');
}
$FM_PATH = FM_PATH;
fm_redirect(FM_SELF_URL . '?p=' . urlencode($FM_PATH));
}
Owner
|
PR #1244 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
this change resolves #744 by adding the option to able to download multiple files and browse while downloading.
Signed-off-by: Vadászi Attila vadaszi.attila@bitecode.hu