diff --git a/app/Views/client_basic_info.php b/app/Views/client_basic_info.php index 17722d1c..b1d2ab8a 100755 --- a/app/Views/client_basic_info.php +++ b/app/Views/client_basic_info.php @@ -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", "/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", "/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", "/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", "/public/assets/images/avatar_2x.png"); + } \ No newline at end of file