views:

90

answers:

2

I have a web form that will upload a user-selected file. I need to get the icon file that is registered on the user's system for this file to upload it along with the uploaded file. How can I access a local file and extract its associated icon in the browser with JavaScript?

If this can be done, and you know how, thanks in advance.

+5  A: 

You can't access local files of the user with JS. This is prevented by the security sandbox model of all browsers explained here http://en.wikipedia.org/wiki/JavaScript#Security and http://en.wikipedia.org/wiki/Same_origin_policy.

But there is a way on Mozilla based browser, set netscape.security.PrivilegeManager.enablePrivilege(”UniversalFileRead”) in about:config, see details here: http://cakebaker.wordpress.com/2006/03/29/file-upload-with-selenium/

powtac
Actually, you CAN get file data via the W3C FileList API which is based on Firefox's FileList API.
Eli Grey
A: 

In Firefox you can use the moz-icon://filename[?size] URI scheme.

For example: moz-icon://someDocument.pdf?size=32 will display a 32x32 pixel image for whatever image is registered on the user's system for the filename extension.

Eli Grey