温馨提示×

Windows中fakepath路径问题怎么解决

小亿
671
2023-08-11 03:04:30
栏目: 智能运维

在 Windows 中,当我们在网页中上传文件时,浏览器会将文件的完整路径显示为 fakepath。这是出于安全考虑,以防止网站获取用户计算机上的真实文件路径。

如果你希望获取真实的文件路径,可以使用以下方法之一解决 fakepath 路径问题:

  1. 使用 JavaScript 将 fakepath 替换为真实路径:
var filePath = document.getElementById("fileInput").value;
filePath = filePath.replace("C:\\fakepath\\", "");
console.log(filePath);
  1. 只获取文件名而不包含路径:
var fileName = document.getElementById("fileInput").files[0].name;
console.log(fileName);

请注意,这些方法仅适用于在网页中上传文件时。在其他情况下,例如在本地运行的程序中使用文件路径,fakepath 不会出现。

希望对你有所帮助!

0