Get selected uploaded file name in input file by jQuery without fake path

Uploaded file value comes with a fake path, how to get filename without a fake path.

In this code, how to get filename without full path, only use the file name which is upload in the input file.  In other words, get an image or file temp name by jquery when user upload file in input filed.

like C:\fakepath\finalimage.jpg, only get finalimage.jpg

use below code, get the input type file value.

var changeFileName = changeFile.replace(/^.*[\\\/]/, '');
Detail code of get upload file name without fake path HTML with jQuery.

HTML Code

<div id="uploadImageBug" class="uploadImageBug">
<input type="file" id="fileUploadBug" />
</div>

jQuery Code

(function(){
jQuery('#uploadImageBug input[type="file"]').change(function(){
var getFileName = jQuery(this).val(); 
var changeFileName = getFileName.replace(/^.*[\\\/]/, '');
console.log(changeFileName);
});
})();

Leave a Reply

Your email address will not be published. Required fields are marked *