开发者

Browse files with specific extention in web browser?

In our web based application we allow users to upload files.

I wonder if after clicking browse button we can restrict the list of available files to be uploaded by file extension. *.zip for example. Just to give the user easier way to find, select and click the file name.

I guess there will be开发者_C百科 javascript base solution but can I do it without javascript?

NOTE: this questions is only about making the browse dialogue to display less files.


In theory, <input type="file" accept="application/zip"> should work. Sadly, no mayor browser supports it...

You can use JavaScript to allow zip files only, but they will still appear in the list.

Edit:

For restriction purposes, you could use JavaScript, but you'd still have to perform server-side verification (with PHP, for example).

For a more convenient dialogue, you could use a Flash or Java Applet solution.

Links:

Flash Uploader

JUpload

Both allow you to limit the file extensions (among many other customizations).


It is not possible to set a file extension filter for the file browse dialogue. The best you can do client-side is to pass the file name through a javascript function on submit, and parse the extension to see if it is legal before proceeding with the upload.

Always bare in mind that your users will still be able to upload any files they choose, no-matter what you try to do client-side. You should always have a server-side check to ensure people aren't uploading malicious scripts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜