I created one webpage where I want to download only a text file using JavaScript, and it works fine.
Using below javascript, checking the txt download file 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>
Live demo here
Problem . If I change the .exe file extension to .txt manually, it also loads because I only check the file extension. So my question is how to protect against an exe file (which is manually changed to txt ) for download.
I want to stop loading exe, jar files, which are changed or renamed forcibly or manually.