Mithun Sreedharan
Mithun Sreedharan

Reputation: 51272

jQuery val() function and file input field in IE

I have a file inputfile

<input tye='file' id='funPic' name='funPic' />

I need to get the name of the selected file,

$('#funPic').val() in Firefox and Chrome gives abc.jpg where as IE7 & IE8 gives c:\xyz\abc.jpg

Why is this? I need only the abc.jpg part.

Upvotes: 2

Views: 2088

Answers (1)

Andy E
Andy E

Reputation: 344567

Use

$('#funPic').val().split("\\").pop();

Mozilla and other browsers don't give the full path for security reasons. IE will only give the filename when the page runs outside the local security zone.

http://msdn.microsoft.com/en-us/library/ms535126(v=VS.85).aspx

Upvotes: 5

Related Questions