如何在使用< input type =" file"时使用上传文件的JQUERY获取完整路径>>在所有浏览器中,为什么IE,Chrome会给出“c:/ fakepath / filname”返回? [英] How to get Full Path using JQUERY of a uploaded file when use <input type="file"> in all browser and why IE,Chrome gives "c:/fakepath/filname" return?

查看:122
本文介绍了如何在使用< input type =" file"时使用上传文件的JQUERY获取完整路径>>在所有浏览器中,为什么IE,Chrome会给出“c:/ fakepath / filname”返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSF CODE LINK HERE



在这段代码中,我使用 < input type =file> 用户浏览任何文件。

HTML

 < input class =file_upfiletype =file/> 
< input class =btn_showpathtype =buttonvalue =显示完整路径/>
< ; p class =p_upfilepath>完整路径将显示在这里< p>

函数,但只返回 FILENAME.txt(eg) in $('。classname').val(); strong> FireFox ,如果我在 IE Chrome 中使用相同的代码,则返回C:/fakepath/myfilename.txt

jQuery

  / * < p>只显示文件名,我想要一个文件
的完整路径,如c:\\ \ something \folder\filename.txt* /

$('。btn_showpath')。click(function(){
var getpath = $('。file_upfile')。 VAL();
$('。p_upfilepath')。slideUp(function(){
$('。p_upfilepath')。text('''+ getpath +''')。slideDown();
});
});

CSS

  .p_upfilepath {
background:#aaaaaa;
padding:3px 10px;
width:auto;
颜色:#555555;
}


解决方案

无法获取文件的完整路径。



或文件实际存储在远程用户计算机上,因此其文件位于何处。
某些浏览器具有防止JavaScript或任何脚本知道您文件的本地完整路径的安全功能。它是有道理的 - 作为一个客户端,你不希望服务器知道你的本地机器的文件系统。

JSF CODE LINK HERE

Here in this code i use <input type="file> and i want a full path after user browse any file.

HTML

<input class="file_upfile" type="file" />
<input class="btn_showpath" type="button" value="Show Full Path"/>
<p class="p_upfilepath">Full path will display here<p>

Here i use $('.classname').val(); function but return only FILENAME.txt(e.g) in FireFox and if i use this same code in IE and Chrome return "C:/fakepath/myfilename.txt"

jQuery

/* Here <p> show only file name, I want a full path of file
   like "c:\something\folder\filename.txt"   */

$('.btn_showpath').click(function(){
    var getpath = $('.file_upfile').val();
    $('.p_upfilepath').slideUp(function(){
        $('.p_upfilepath').text('"'+getpath+'"').slideDown();
    });
});

CSS

.p_upfilepath{
    background:#aaaaaa;
    padding:3px 10px;
    width:auto;
    color:#555555;
}

解决方案

I think you cant get full path of file .

Or file is stored actually on remote users machine so its dosent matter where is a file located . Some browsers have a security feature that prevents javascript or any script from knowing your file's local full path. It makes sense - as a client, you don't want the server to know your local machine's filesystem.

这篇关于如何在使用&lt; input type =&quot; file&quot;时使用上传文件的JQUERY获取完整路径&gt;&gt;在所有浏览器中,为什么IE,Chrome会给出“c:/ fakepath / filname”返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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