I try to get the upload value when the input field‘s change event occurs
But I get this value on Chrome,
C:\fakepath\winnie-the-pooh.jpg
So I split the \ and the the last item in the array.
jquery,
$("#upload").change(function(){
var fragment = $("#upload").val();
var array_fragment = fragment.split('\/');
alert($(array_fragment).last()[0]);
});
But I still get C:\fakepath\winnie-the-pooh.jpg instead of winnie-the-pooh.jpg on Chrome.
How can I make it worked?
the html,
<input type="file" name="image" id="upload"/>
You need to split on
\, not/:Ideally though, you’d split on either. Fortunately,
splittakes a regular expression:That regex basically means “
\or/“—the pipe operator,|, is the “or”, and the/characters at the start and end signify that a regular expression is in between.