jquery - 从本地驱动器加载img [英] Jquery - load img from local Drive

查看:79
本文介绍了jquery - 从本地驱动器加载img的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HTML标签:




用户选择文件,我想预览此文件内部的图像大小为onchange事件:

$ $ p $ $($)$ $ $ $(document).ready(function(){
$(#bigPicture)。change(function(){
alert($(#bigPicture)。val());
$(#test1)。attr(src ,$(#bigPicture)。val());
});
});

我有很奇怪的行为:

1)as alert我得到了 C:\ fakepath \\ [文件名] ,尽管我在Ubuntu机器+谷歌浏览器中。



2)我的文件不会被加载到img标签中。

<3>在FireFox上,我只有[文件名]没有路径的警报。并且图像不被渲染。



我做错了什么?
这些浏览器是否存在某种安全限制?

解决方案

http://dev.w3.org/html5/spec/Overview.html#file-upload-state < a

$ b


由于历史原因,IDL
属性的前缀为
字符串C:\\ \\fakepath\。一些传统的
用户代理实际上包含了完整的
路径(这是一个安全性
漏洞)。



<
$ b


在获取时,它必须返回字符串
C:\ fakepath \后跟选定文件的列表
中的第一个文件的
文件名(如果有的话),或者如果列表为空,则为
空字符串。在
设置上,如果新值是空的
字符串,它必须清空
选定文件的列表;否则,它必须
抛出一个INVALID_STATE_ERR异常。



I have the following HTML Tags:

User select file and I want to preview this file inside image size as onchange event:

$(document).ready(function(){
    $("#bigPicture").change(function() {
    alert($("#bigPicture").val());
    $("#test1").attr("src",$("#bigPicture").val());
     });
});

I have very weird behavior:

1) as alert I got C:\fakepath\\[file name] although I'm on Ubuntu machine + Google Chrome.

2) my file is not loaded rendered in img tag.

3) on FireFox i got only [filename] alert without path. and the image is not rendered as well.

Am I doing something wrong? Is it some kind of security restriction on these browsers?

解决方案

http://dev.w3.org/html5/spec/Overview.html#file-upload-state

For historical reasons, the value IDL attribute prefixes the filename with the string "C:\fakepath\". Some legacy user agents actually included the full path (which was a security vulnerability).

filename

On getting, it must return the string "C:\fakepath\" followed by the filename of the first file in the list of selected files, if any, or the empty string if the list is empty. On setting, if the new value is the empty string, it must empty the list of selected files; otherwise, it must throw an INVALID_STATE_ERR exception.

这篇关于jquery - 从本地驱动器加载img的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆