< input type ='file'> IE提供完整路径,FF只给文件名(或目录浏览) [英] <input type='file'> IE Gives full path, FF gives only filename (or directory browse)
问题描述
可能重复:
上传文件时无法获取完整地址
我需要完整的路径。
我试图给出本地书签的功能,即用户想要在本地PC上访问 c:\MyStuff\Myfile.xls
。
如何保存/获取该值,而无需制作教程帮助页来了解如何剪切和粘贴 c:\MyStuff\Myfile.xls
。
以下代码适用于IE7。
我理解它是一个安全问题,但我不需要保存它们的选择,甚至不需要使用enctype / multiform,甚至不需要提交任何内容,我只需要获取它们选择的路径。
< html>
< head>
< title>< / title>
< / head>
< body>
< script language =JavaScripttype =text / javascript>
<! -
vic = 0;
document.write('< style> .debug {VISIBILITY:visible; POSITION:absolute; TOP:500px; z-Index:100;}< / style>')
<! - --->
< / script>
从目录中选择一个文件,然后保存路径< br>
< input type =fileid =dirvalue =dirstyle =width:0px; >
< input type =buttonvalue =保存路径onclick =javascript:SavePath(); >
< script language =JavaScripttype =text / javascript>
<! - 在ie8上运行而不是ff。
函数SavePath(){
if(document.getElementById('dir')。value ==''){
alert('从目录中选择一个文件');
return;
}
Path = document.getElementById('dir')。value.substring(0,document.getElementById('dir')。value.lastIndexOf('\\\'));
alert('variable Path ='+ Path +'\\\');
}
// - >
< / script>
< / body>
< / html>
你不会明白的!
抱歉,是没有办法的。
(即使浏览器包含整个路径,如果它不是一个Windows box你不会得到 \\
path-separators。你可能会得到 /
...或者别的什么东西。)
如何保存/获取该值,而无需制作教程帮助页来了解如何剪切和粘贴
您可以尝试鼓励他们将文件图标拖放到简单的文本字段。在许多浏览器中都会粘贴路径名。
language =JavaScript
您不需要这样做。
javascript:
你不需要那个。
<! -
...
<!---->
你不需要那个。 (如果你这样做的话,不匹配的 -
s将是无效的。)
<! - 在ie8上工作而不是ff。
不正确的JavaScript评论。
Possible Duplicate:
Can’t get the complete address while uploading a file
I need the full path.
I'm trying to give the functionality of local bookmarks, ie user wants to access c:\MyStuff\Myfile.xls
on their local Pc.
How do I save/get that value without having to make a tutorial help page on how to cut and paste c:\MyStuff\Myfile.xls
.
The below code works in IE7. I understand the point about it being a security issue, but I don't need to save their choice or even use enctype/multiform, or even submit anything, i just need to get the path they selected.
<html>
<head>
<title></title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
vic=0;
document.write('<style> .debug {VISIBILITY: visible; POSITION: absolute; TOP: 500px; z-Index:100; }</style>')
<!---->
</script>
Select a file from directory then save the path<br>
<input type="file" id="dir" value="dir" style="width:0px;" >
<input type="button" value="Save Path" onclick="javascript:SavePath();" >
<script language="JavaScript" type="text/javascript">
<!-- works on ie8 not ff.
function SavePath(){
if (document.getElementById('dir').value==''){
alert('Select a file from the directory');
return;
}
Path=document.getElementById('dir').value.substring(0,document.getElementById('dir').value.lastIndexOf('\\'));
alert('variable Path='+Path+'\\ ');
}
//-->
</script>
</body>
</html>
I need the full path.
You won't get it!
Sorry, there is no way.
(You can't rely on anything useful being in the filename at all: even if the browser includes the whole path, if it ain't a Windows box you're not going to get \\
path-separators. You might get /
... or something else completely.)
How do I save/get that value without having to make a tutorial help page on how to cut and paste
You could try encouraging them to drag-and-drop the file icon to a simple text field. In many browsers that will paste in the pathname.
language="JavaScript"
You don't need that.
javascript:
You don't need that.
<!--
...
<!---->
You don't need that. (And if you did, the mismatched --
s would be invalid.)
<!-- works on ie8 not ff.
Not properly a JavaScript comment.
这篇关于< input type ='file'> IE提供完整路径,FF只给文件名(或目录浏览)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!