0

I need to allow select file dialog to accept any file type except some specific type, for example I need to make the dialog displays everything except for .exe files,

Baha' Al-Khateib
  • 307
  • 3
  • 10
  • take a look at this http://stackoverflow.com/questions/3521122/html-input-type-file-apply-a-filter – yantaq Jul 11 '15 at 01:10

1 Answers1

0

I see this question is already exist and have good answer. Please check the bellow link Validation of file extension before uploading file

var _validFileExtensions = [".jpg", ".jpeg", ".bmp", ".gif", ".png"];    
function Validate(oForm) {
    var arrInputs = oForm.getElementsByTagName("input");
    for (var i = 0; i < arrInputs.length; i++) {
        var oInput = arrInputs[i];
        if (oInput.type == "file") {
            var sFileName = oInput.value;
            if (sFileName.length > 0) {
                var blnValid = false;
                for (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 + " is 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>
Community
  • 1
  • 1
Dinidu Hewage
  • 1,977
  • 6
  • 39
  • 45