I've been seraching for this for quite a long time, but found no good answer.
I have four fields which accept files from user,
<form method="post" action="upload" target="_blank" enctype="multipart/form-data" style="position: absolute; right: 0%; top: 2%;">
Left File : <input type="file" name="dataFile" id="fileChooser" /><br><br>
Right File : <input type="file" name="dataFile" id="fileChooser" /><br><br>
Config File :<input type="file" name="dataFile" id="fileChooser" /><br><br>
my File : <input type="file" name="dataFile" id="fileChooser" /><br><br>
upload<input type="submit" value="Upload" multiple="multiple" />
</form>
how to identify if the user chooses to upload same file all the four times and prevent it (i.e duplicate uploads)?
this may be on the JSP side or on the sevlet java side. Using commons file upload. I've found on my search here that I need to use DigestOutputStream, but no where I could find how to use it and was of no use.
---------------------------------------------EDIT--------------------------------------
Based on the answers below, I've updated my code as follows,
<form method="post" name="myform" action="upload" target="_blank" enctype="multipart/form-data" style="position: absolute; right: 0%; top: 2%;">
Left File : <input type="file" name="dataFile1" id="fileChooser1" /><br><br>
Right File : <input type="file" name="dataFile2" id="fileChooser2" /><br><br>
Config File :<input type="file" name="dataFile3" id="fileChooser3" /><br><br>
Geco File : <input type="file" name="dataFile4" id="fileChooser4" /><br><br>
</form>
<button type="button" onclick="ValidateFile()" style="position: absolute; right: 8%; top: 20%;">Click to Upload</button>
<script type='text/javascript'>
function ValidateFile()
{
var FileName1 = document.getElementById("fileChooser1");
var FileName2 = document.getElementById("fileChooser2");
var FileName3 = document.getElementById("fileChooser3");
var FileName4 = document.getElementById("fileChooser4");
if(FileName1 == FileName2)
{
alert("Same file cannot be uploaded!");
}
document.myform.submit(); // This works fine, but the alert doesn't. Tried .value and .value() also still doesn't work.
}
</script>
Still the code doesn't work what is my mistake?