javascript get path to current file code example

Example 1: how to use javascript to get full file path

const onChange = (event) => {
  const value = event.target.value;

  // this will return C:\fakepath\somefile.ext
  console.log(value);

  const files = event.target.files;

  //this will return an ARRAY of File object
  console.log(files);
}

return (
 <input type="file" onChange={onChange} />
)
/* Found from Stack Overflow */

Example 2: js get file location

var url,foldersAndFile,folders,folderpath,protocol,host,ourLocation;
    url = window.location;
    
    foldersAndFile = url.pathname.split("/");
    folders = foldersAndFile.slice(0,foldersAndFile.length-1);
    folderpath = folders.join("/");
    
    protocol = url.protocol+"//";
    host = url.host;
    
    ourLocation=protocol+host+folderpath;
    
    return ourLocation;// http://google.com/search