0

I am trying to include a File Upload integration on an ASP.NET page using the HTML input control.

<input type="file" id="strImageName" runat="server" class="inputtxt" size="44" maxlength="100" contentEditable="false" NAME="strImageName">

I am accepting a variety of file types, but definitely not HTML. When I use the control:

I see two different behaviors wrt the filtered file extensions, one in IE and the other in Chrome. File Upload Control on IE On IE

File Upload Control on Chrome On Chrome

Can you please help me emulate the behavior of Chrome on IE?

Thanks,

Anil

Laurent S.
  • 6,816
  • 2
  • 28
  • 40
Anil V K Babu
  • 107
  • 1
  • 2
  • 8
  • Both screenshots show an IE icon. Also you should just check the file type serverside. – CodeCaster Mar 28 '14 at 09:25
  • This question will presumably be closed. It is important to mention that you should ALWAYS check for file type on server, although you can almost never be 100% sure the file will be of the expected type. That's why ideally you should store uploaded files outside of the webroot and access it back with a custom handler, ensuring no one can actually execute any code server-side from an HTTP request – Laurent S. Mar 28 '14 at 09:27
  • I have a validation available both at the server and at the client. However, its a usability issue that I am trying to address here.... – Anil V K Babu Mar 28 '14 at 09:41

1 Answers1

2

Have you tried the accept attribute ?

<input type="file" accept=".gif, .jpg, .png" ...>

Specifying the MIME-type(s) only might also work:

<input type="file" accept="image/*" ...>

HTML input accept Attribute

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • I am looking out at removing all and just show "All files", because I have around 15 different file types which are being accessed – Anil V K Babu Mar 28 '14 at 09:42
  • @AnilVKBabu What happens if you try `accept="*/*"` or just `accept="*"`? And, are we also talking about 15 different _MIME-types_, if they are all images then the `accept="image/*"` should cover it for all of them. –  Mar 28 '14 at 09:46