+ 1
I have been trying to input an image but it's not working
Html
1 Réponse
0
<input type="file" name = "fileName" id = "file">
Here file can be anything. Not only jpg file even XML, pdf and others.
<--------Function to Check file type ----->
var validExt = ".png, .gif, .jpeg, .jpg";
function fileExtValidate(fdata) {
var filePath = fdata.value;
var getFileExt = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();
var pos = validExt.indexOf(getFileExt);
if(pos < 0) {
alert("This file is not allowed, please upload valid file.");
return false;
} else {
return true;
}
}
<--------Function to Check File Size --------->
var maxSize = '1024';
function fileSizeValidate(fdata) {
if (fdata.files && fdata.files[0]) {
var fsize = fdata.files[0].size/1024;
if(fsize > maxSize) {
alert('Maximum file size exceed, This file size is: ' + fsize + "KB");
return false;
} else {
return true;
}
}
}