javascript - Exclude some file extension from upload dialog -
i need allow select file dialog accept file type except specific type, example need make dialog displays except .exe files,
i see question exist , have answer. please check bellow link validation of file extension before uploading file
var _validfileextensions = [".jpg", ".jpeg", ".bmp", ".gif", ".png"]; function validate(oform) { var arrinputs = oform.getelementsbytagname("input"); (var = 0; < arrinputs.length; i++) { var oinput = arrinputs[i]; if (oinput.type == "file") { var sfilename = oinput.value; if (sfilename.length > 0) { var blnvalid = false; (var j = 0; j < _validfileextensions.length; j++) { var scurextension = _validfileextensions[j]; if (sfilename.substr(sfilename.length - scurextension.length, scurextension.length).tolowercase() == scurextension.tolowercase()) { blnvalid = true; break; } } if (!blnvalid) { alert("sorry, " + sfilename + " invalid, allowed extensions are: " + _validfileextensions.join(", ")); return false; } } } } return true; }
<form onsubmit="return validate(this);"> file: <input type="file" name="my file" /><br /> <input type="submit" value="submit" /> </form>
Comments
Post a Comment