FIX_ClientLOGOConsoleaddedWorkingButReportedtheIssues

This commit is contained in:
sanjeev.p 2026-02-13 14:20:33 +05:30
parent e2a93aeb2e
commit 32cafb2c00

View File

@ -415,44 +415,60 @@ input:checked + .slider:before {
function validateFile(input) {
if (!input.files || !input.files[0]) return;
const file = input.files[0];
const allowedExtensions = ["jpg", "jpeg", "png"];
const fileExtension = file.name.split(".").pop().toLowerCase();
const fileSize = file.size / 1024; // KB
// Log Initial Info
console.log("File Selected:", file.name);
console.log("File Size:", fileSize.toFixed(2) + " KB");
// Check if the file extension is allowed
if (!allowedExtensions.includes(fileExtension)) {
toastr.warning('Only JPG, JPEG, PNG files are allowed.', 'Invalid file type.');
$("#uploadPreview").attr("src", "<?= base_url()?>/public/assets/images/avatar_2x.png");
input.value = "";
resetImageInput(input);
return;
}
// Check file size
const fileSize = file.size / 1024; // in KB
if (fileSize > 200) {
console.error("Validation Failed: File too large (" + fileSize.toFixed(2) + " KB)");
toastr.warning('Maximum file size allowed is 200KB.', 'File size exceeds limit.');
$("#uploadPreview").attr("src", "<?= base_url()?>/public/assets/images/avatar_2x.png");
input.value = "";
resetImageInput(input);
return;
}
// Check image dimensions
const img = new Image();
img.src = URL.createObjectURL(file);
img.onload = function() {
console.log("Dimensions Detected:", this.width + "x" + this.height);
if (this.width !== 100 || this.height !== 100) {
console.error("Validation Failed: Wrong dimensions.");
toastr.warning('Image dimensions should be 100x100 pixels.', 'Invalid image dimensions.');
$("#uploadPreview").attr("src", "<?= base_url()?>/public/assets/images/avatar_2x.png");
}
resetImageInput(input); // CRITICAL: This stops the file from being sent
}else {
console.log("Validation Passed: Image is 100x100 and under 200KB.");
// If both size and dimensions are valid, you can proceed with your logic here
// For example, you can display the image
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById("uploadPreview").src = e.target.result;
$("#uploadPreview").attr("src", e.target.result);
};
reader.readAsDataURL(file);
}
};
img.src = URL.createObjectURL(file);
}
// Helper function to clear the preview and the file input
function resetImageInput(input) {
input.value = ""; // This clears the file so it won't be submitted
$("#uploadPreview").attr("src", "<?= base_url()?>/public/assets/images/avatar_2x.png");
}
</script>