0

I am implementing file upload functionality in this way

<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="UploadServlet" method="post"
                        enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>
</body>

Now I want to restrict the user with some file types means when browse window will open he will be able to select all the files except .bin & .dat.

Means user will not be able to see that files with type .bin and .bat others he can see it and can go upload them.

I am familiar with accept attribute but, but it's not useful in my case because user should be able to select any file type except these two.

So how can achieve this without validation ?

I want to provide such a functionality that when user clicks on browse button and open a browse window to select a file , he should be able to see only files without .bin or .dat extension

Is there any way to do this?

Thanks,

Java
  • 2,371
  • 8
  • 44
  • 82
  • Take a look gere: http://stackoverflow.com/questions/181214/file-input-accept-attribute-is-it-useful – Deividi Cavarzan May 31 '13 at 13:44
  • Thanks for quick response, But using `accept` we have to specify file types which we want to allow to user select, and we can't mention all the file types in `accept`. we just don't want to see specified file types to user ,so there will be no chance to select them, & it will reduce our validation also. – Java May 31 '13 at 13:49
  • Ok, maybe you need to do this validation via javascript in that case... – Deividi Cavarzan May 31 '13 at 13:58
  • "*Now I want to restrict the user with some file types means when browse window will open he will be able to select all the files except `.bin` & `.dat`*". This not defined in the HTML specification. "*So how can achieve this without validation ?*". No you **never**. At anytime, the client side validation is always wonky (you should do it for the ease of use but you can never rely upon it). Do it right on the server side (must). – Lion Jun 01 '13 at 03:45
  • @Lion so you mean to say user will able to see `.bin & .dat `files but we have to provide client side validation if they select such type of file.right? – Java Jun 01 '13 at 03:54
  • @what should I need to do on server side ? – Java Jun 01 '13 at 04:01
  • A user can upload any type of files using the file browser. We can't prevent users from picking up only a specific category of files like `.bin` and/or `.dat` as you say. Validation is mandatory. You can do validation on both sides, on the server-side as well as on the client-side but one can never trust the client-side validation. It should however be done for easy interactions. The validation is relied upon only when you achieve it on the server side. If I were you, then most of the time, I would be using a file-upload-widget that could upload files with client-side validation. – Lion Jun 01 '13 at 04:03

0 Answers0