how to get the name of an uploaded file code example
Example 1: get uploaded file name
fake_path=document.getElementById('FileUpload1').value
alert(fake_path.split("\\").pop())
Example 2: javascript - get the filename and extension from input type=file
//Use lastIndexOf to get the last \ as an index and use substr to get the remaining string starting from the last index of \
function getFileNameWithExt(event) {
if (!event || !event.target || !event.target.files || event.target.files.length === 0) {
return;
}
const name = event.target.files[0].name;
const lastDot = name.lastIndexOf('.');
const fileName = name.substring(0, lastDot);
const ext = name.substring(lastDot + 1);
outputfile.value = fileName;
extension.value = ext;
}
Output Filename
Extension