Jump to content

input type='file', controlling the file type displayed.


praveenhotha

Recommended Posts

When I click the browse option, it lists all the files present in the folder but if i cancel after selecting for eg. an html file, the second time I click the browse button, it displays only the html files in the folder.

 

Can I do this on the first click of the browse button? I want to control the files shown as I know what type of files need to be uploaded.

what ever you want to do - give up - it can be circumvented - the only thing you can do reliably is to check teh mime type of teh uploaded file - if that is ok continue if not tell the user.

 

You can enhacne this with a nasty javascript check to see what the file extension is (but don't actually trust this) - if its not what you expect then you can prevent the upload.

you can use the accept attribute to specify what it should allow but again this cannot be relied upon and I have never used it so don't know how it acts on differing operating systems/browsers indeed I have read that some browsers completely ignore it...

 

<input type="file" accept="image/jpeg, text/css, image/png" />

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.