浏览器上传文件的问题

发布于 2024-09-06 18:00:40 字数 227 浏览 0 评论 0原文

var file_upload=document.getElementById('图片上传').value;

该代码在两个浏览器中返回不同的值。

在 firefox 中,ie 返回 'filename.ext' 示例:test.jpg

但在 opera 中返回 'fullpath\filename.ext 示例:C:\fake_path\test.jpg

有谁知道这个问题吗

var file_upload=document.getElementById('picture-upload').value;

The code returns diffrent values in two browsers.

in firefox,ie returns 'filename.ext' example: test.jpg

but in opera returns 'fullpath\filename.ext example:C:\fake_path\test.jpg

Is any one knows the problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2024-09-13 18:00:40

IE6 还会为您提供完整路径,而较新的浏览器仅提供文件名。这是为了安全。

我会检查名称中是否存在反斜杠或正斜杠,如果存在,则删除路径。

if(/\\/.test(value)){
    value = value.split("\")[value.split("\").length-1];
}else 
if(/\//.test(value)){
    value = value.split("/")[value.split("/").length-1];
}

(该代码可能会收紧)

IE6 will also give you a full path, while newer browsers only give the file name. It's for security.

I would check for back or forward slashes in the name and if the exist, strip off the path.

if(/\\/.test(value)){
    value = value.split("\")[value.split("\").length-1];
}else 
if(/\//.test(value)){
    value = value.split("/")[value.split("/").length-1];
}

(that code could probably be tightened up)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文