FileType Validations JavaScript
To upload only specific type of files from users, we need to restrict them to upload only specific type of files. Following example will demonstrates the same for only uplod of word files.
<html> <head> <title>JavaScript Validation</title> <script type="text/javascript"> function Checkfiles() { var fup = document.getElementById('filename'); var fileName = fup.value; var ext = fileName.substring(fileName.lastIndexOf('.') + 1); if(ext =="doc" || ext=="docx") { return true; } else { alert("Upload word files only"); return false; } } </script> </head> <body> <form name="xx" action="second.php" method="post" enctype="multipart/form-data" onsubmit="return Checkfiles();""> <input type="file" name="file_uploading" id="filename"> <input type="submit" value="Submit" name="uploadfile"> </form> </body> </html>