views:

47

answers:

1

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.

+3  A: 

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

Andy E
And I don't believe any browser is **required** to provide the actual filename either, only recommended...
gnarf