I created one web page where i want to upload only text file using JavaScript and it is working fine.
Using below JavaScript, it is checking upload file is txt or not?
<script>
function checkExt() {
if(document.mainForm.myfile.value.lastIndexOf(".txt")==-1) {
alert("Please upload only .txt extention file");
return false;
}
}
</script>
<form name="mainForm">
<input type="file" name="myfile" onchange="checkExt();"/>
</form>
Problem: If I change extension of file .exe to .txt manually then it is also being upload because i'm checking file's extension only. So My question is how to protect from exe file (which is Manually changed to txt) to upload.
I want to stop upload exe, jar files which is changed or renamed forcefully or manually.