3
Well, I’m trying to validate max_size on js, but since I don’t understand much, I was only able to validate the accepted formats (jpg, png, etc...)
<input type="file" name="photo" id="photo" onchange="checkfile(this);" />
function checkfile(sender) {
var validExts = new Array(".zip", ".rar", ".pdf", ".jpeg", ".jpg", ".png", ".tif", ".gif", ".JPG");
var fileExt = sender.value;
fileExt = fileExt.substring(fileExt.lastIndexOf('.'));
if (validExts.indexOf(fileExt) < 0) {
alert("Invalid file selected, valid files are of " +
validExts.toString() + " types.");
return false;
}
else return true;
}
I have an example on hand, but do not know how to put together with the checkthis
var uploadField = document.getElementById("file");
uploadField.onchange = function() {
if(this.files[0].size > 307200){
alert("File is too big!");
this.value = "";
};
};
begins by modifying the
file
forphoto
in the variableuploadeField
, and then you can paste your example normally into a tagscript
or documentjs
. Tell me what happened.– Edilson
Nothing has changed, it does not check the size to return the message "File is Too big"
– Felipe Silva
shows how you made that change.
– Edilson