I'm working mostly in FF, and this code works perfectly for displaying the uploaded item's filename (without path). On all the other browsers I've tested (Chrome, Safari, Opera), you see fakepath. But when I tried various suggested methods to get rid of 'fakepath', FF stops working entirely. And sometimes even what seems to be a Chrome-friendly approach shows up with the odd filename of "Object object", even as it breaks in FF. The whole 'fakepath' thing is bound to confuse the intended audience of less-savvy users, so I'd like to strip it out if I could. But since FF behaves as I want from the get-go, is there a way to only strip the fakepath part if the browser != FF? And if so, what will get me actual stripped-filename (as opposed to Object object)?
This is the version that works in FF:
$('input[name="file"]').change(function(){
var filename = $(this).val();
$('<span class="fileshow">'+ filename +'</span>').insertAfter($(this));
});
And this gets me Object object in Chrome, so something's wrong but I'm not sure what.
$('input[name="file"]').change(function(){
var filename = $(this).val(this.files && this.files.length ?
this.files[0].name : this.value.replace(/^C:\\fakepath\\/i, ''));
$('<span class="fileshow">'+ filename +'</span>').insertAfter($(this));
});
Thanks in advance for the help.