jQuery Get the filename from a file input field

The filepath is stored in the field value but, depending on your browser and OS, it can contain confusing pathnames for the user, such as "fakepath". You can strip the filename from the end by splitting the string, making sure to account for forward and backslash.
$('input[type=file]').val().split('/').pop().split('\\').pop();
Posted by
Snippet Viewed 6630 times.

Share your jQuery code snippets:

  • Get some recognition & link back to your site.

 

Submit | Browse

Most Recent jquery snippets

Most Viewed