【问题标题】:chrome's file input element, full path retrieval and command lineschrome的文件输入元素、全路径检索和命令行
【发布时间】:2015-07-21 20:40:36
【问题描述】:

知道如何从 chrome 的文件输入元素中检索完整文件路径吗?

HTML:

<img id="person" src="http://fc09.deviantart.net/fs71/f/2010/330/9/e/profile_icon_by_art311-d33mwsf.png" />
<input id="file" type="file" style="display:none" />

jQuery:

$('#person').click(function(){
    $('#file').click()
});

$('#file').change(function(){
    person.src = this.value;
});

问题:

当点击图片并选择文件时,IE中的输入显示文件的完整路径c:/media/me.png,该值存储为file.value。然而,chrome中的输入只显示文件名me.png,它的值和图像的src属性读取C:\fakepath\me.png???

我已尝试添加:

--disable-web-security

和/或

--allow-file-access-from-files

到我的 chrome 快捷方式 Targetcmd.exe 没有成功???

我有什么遗漏吗?

【问题讨论】:

  • 在这里发表评论,因为我也想知道答案。我也有完全一样的问题。我几乎尝试了一切。我开始认为这在 Chrome 中是不可能的。
  • @Chris 为支持老兄欢呼,已将其留待答案,但似乎只是 chrome 安全功能,尚未找到解决方法,但仍在寻找...

标签: jquery google-chrome file-upload command-line


【解决方案1】:

我终于找到了解决问题的方法,我会在这里发布它,也许它也会对你有所帮助。在 Chrome 中获取绝对路径几乎是不可能的,但是您可以使用一个临时路径来访问该文件。要获取临时文件,您的代码将如下所示:

$('#file').change(function(e){
    person.src = URL.createObjectURL(e.target.files[0]);
});

https://jsfiddle.net/upcxxvay/1/

我希望这可以帮助你喜欢它帮助我:)

【讨论】:

  • 干杯克里斯,但无论如何我都使用URL.createObjectURL,我只是希望有一种方法可以显示完整路径!
猜你喜欢
  • 2019-05-01
  • 1970-01-01
  • 2012-12-04
  • 1970-01-01
  • 2019-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多