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

Validate file size before upload #7383

Open
wants to merge 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion templates/documents/general_upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,29 @@
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*}

<script>
function checkFileSize() {
var fileInput = document.querySelector('input[type="file"]');
var totalSize = 0;

// Get the size of the selected file
for (var i = 0; i < fileInput.files.length; i++) {
totalSize += fileInput.files[i].size;
}
Comment on lines +20 to +21
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MAX_FILE_SIZE is the maximum allowed size for each individual file, not the combined total size of all files.
So this verification is invalid for our purposes.


// Check if the file size exceeds the maximum allowed size.
if (totalSize > 64000000) {
alert('Total file size exceeds the maximum limit of 64MB.');
// Prevent form submission
return false;
}
// Allow form submission
return true;
}
</script>

<div class="col-sm-12">
<form class="form" method="post" enctype="multipart/form-data" action="{$FORM_ACTION}" onsubmit="return top.restoreSession()">
<form class="form" method="post" enctype="multipart/form-data" action="{$FORM_ACTION}" onsubmit="return checkFileSize()">
Comment on lines -14 to +35
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need to run restoreSession before file check.

<input type="hidden" name="MAX_FILE_SIZE" value="64000000" />
<h3>{if !empty($error)}{$error|text|nl2br}{/if}</h3>
{if (!($patient_id > 0))}
Expand Down