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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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" />

Link to comment
Share on other sites

I think what he wants to do is change what "File Type" is defaulted in the dialog box so that the USER doesn't have to sort through a folder full of .wav files when they are looking to upload a .txt file. Is this correct?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.