Here's how the javascript would basically work:
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function submitForm( theForm )
{
var txt = theForm.FileContents.value;
var lastFew = txt.substring( txt.length - 3, txt.length + 1 );
alert(lastFew)
if (lastFew.toLowerCase() == "pdf")
return true;
alert("Please upload only a PDF file.")
return false;
}
//-->
</SCRIPT>
<form action="upload.jsp" method="post" enctype="multipart/form-data"
onSubmit="return submitForm( this )">
Upload a PDF only
<input name="FileContents" type="FILE" size="45"><br>
<input type="submit" name="submit" value="Upload File">
</form>
Upon submission of the form, this checks the last 3 characters of the input
box.
On the java side of things, you're gonna need to look at the MIME type
(sometimes called the CONTENTSUBTYPE) in the received request. This varies
depending on what API you're using to retrieve and save the bytestream from
the request.
So, do some research on that.
Ian.
-----Original Message-----
From: Ralph Merrick [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 23, 2002 4:07 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED];
[EMAIL PROTECTED]
Subject: Java/Javascript question
Would any one know what Javascript code could check
the following. That with an input type= file, where
you press browse to upload a file, some times people
just type in a file name. In my case only a pdf file
will be uploaded. How could I check that a typed in
name into the textfield will end in '.pdf' and how can
using Java, an uploaded file, although having a pdf
extension, be checked that it is a valid Acrobat file?
Thanks
__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com
--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>