mirror of
https://github.com/itflow-org/itflow
synced 2026-03-24 06:25:40 +00:00
Also added 500MB Limit
This commit is contained in:
@@ -28,25 +28,36 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
const maxFiles = 20; // Set the maximum number of allowed files
|
const maxFiles = 20; // Set the maximum number of allowed files
|
||||||
|
const maxTotalSize = 500 * 1024 * 1024; // 500MB in bytes
|
||||||
|
|
||||||
const fileInput = document.getElementById('fileInput');
|
const fileInput = document.getElementById('fileInput');
|
||||||
const uploadForm = document.getElementById('uploadForm');
|
const uploadForm = document.getElementById('uploadForm');
|
||||||
|
|
||||||
fileInput.addEventListener('change', function () {
|
fileInput.addEventListener('change', function () {
|
||||||
if (fileInput.files.length > maxFiles) {
|
const totalSize = calculateTotalFileSize(fileInput.files);
|
||||||
alert(`You can only upload up to ${maxFiles} files at a time.`);
|
if (fileInput.files.length > maxFiles || totalSize > maxTotalSize) {
|
||||||
|
alert(`You can only upload up to ${maxFiles} files at a time and the total file size must not exceed 500MB.`);
|
||||||
resetFileInput();
|
resetFileInput();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
uploadForm.addEventListener('submit', function (event) {
|
uploadForm.addEventListener('submit', function (event) {
|
||||||
if (fileInput.files.length > maxFiles) {
|
const totalSize = calculateTotalFileSize(fileInput.files);
|
||||||
|
if (fileInput.files.length > maxFiles || totalSize > maxTotalSize) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
alert(`You can only upload up to ${maxFiles} files at a time.`);
|
alert(`You can only upload up to ${maxFiles} files at a time and the total file size must not exceed 500MB.`);
|
||||||
resetFileInput();
|
resetFileInput();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function calculateTotalFileSize(files) {
|
||||||
|
let totalSize = 0;
|
||||||
|
for (const file of files) {
|
||||||
|
totalSize += file.size;
|
||||||
|
}
|
||||||
|
return totalSize;
|
||||||
|
}
|
||||||
|
|
||||||
function resetFileInput() {
|
function resetFileInput() {
|
||||||
fileInput.value = ''; // Clear the selected files
|
fileInput.value = ''; // Clear the selected files
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user