Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
15
rated 0 times [  21] [ 6]  / answers: 1 / hits: 32002  / 12 Years ago, wed, april 25, 2012, 12:00:00

I give user the option of uploading a file like this



<form action=# onsubmit=return Checkfiles(this);>
<center><input type=file id=filename>
<input type=submit value=Go!></center>
</form>


When user uploads the file, I validate the file using the following javascript function



<script type=text/javascript>
function Checkfiles()
{
var fup = document.getElementById('filename');
var fileName = fup.value;
var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
if(ext == pdf )
{
return true;
}
else
{
alert(Upload pdf files only);
fup.focus();
return false;
}
}
</script>


Evertything is working fine with it.

But I want to validate file by some other means and not just by its extension

I will give reason for doing this. I renamed an image file to image.pdf and now its in pdf format but couldnt be opened.



So I want to validate a pdf file in exact way. Is there any other way to check other than by its extension?

Edit

I want to do validation at server end using jsp page. So what should I do for that?

Thanks in ADVANCE :)


More From » jsp

 Answers
6

As far as I know, checking if a pdf actually is a pdf can only be done on server side. You could try and open it with IText or something similar; I bet it throws some sort of exception when you try opening or modifying something else then a PDF.


[#85997] Tuesday, April 24, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
masonm

Total Points: 167
Total Questions: 87
Total Answers: 103

Location: Rwanda
Member since Wed, Jun 8, 2022
2 Years ago
;