如何在< input type ='file'的变化上获得所选文件的完整路径>使用javascript,jquery-ajax? [英] How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax?
问题描述
如何使用< input type ='file'>
< input type =fileid =fileUpload>
< script type =text / javascript>
函数getFilePath(){
$('input [type = file]')。
});
}
< / script>
但filePath var包含只有名称
of选定的文件,而不是完整路径
。
我在网上搜索了它,但是出于安全原因,浏览器(FF,chrome)似乎给出了文件名。
是否有其他方法可以获得完整路径的选择文件?
出于安全原因,浏览器不允许这样做,即浏览器中的JavaScript无法访问文件系统,然而,使用HTML5 File API,只有Firefox提供了一个 mozFullPath
属性,但是如果你尝试获取该值,它将返回一个空字符串:
$('input [type = file]')。change(function(){
console.log(this.files [0] .mozFullPath);
});
所以不要浪费你的时间。
编辑:如果您需要文件路径来读取文件,您可以使用 FileReader API代替。这里有一个相关的问题SO:预览图像上传之前。
How to get full path of file while selecting file using <input type=‘file’>
<input type="file" id="fileUpload">
<script type="text/javascript">
function getFilePath(){
$('input[type=file]').change(function () {
var filePath=$('#fileUpload').val();
});
}
</script>
but the filePath var contains only name
of selected file, not the full path
.
I searched it on net, but it seems that for security reasons browsers (FF,chrome) just give name of file.
Is there any other way to get full path of selected file?
For security reasons browsers do not allow this, i.e. JavaScript in browser has no access to the File System, however using HTML5 File API, only Firefox provides a mozFullPath
property, but if you try to get the value it returns an empty string:
$('input[type=file]').change(function () {
console.log(this.files[0].mozFullPath);
});
So don't waste your time.
edit: If you need the file's path for reading a file you can use the FileReader API instead. Here is a related question on SO: Preview an image before it is uploaded.
这篇关于如何在< input type ='file'的变化上获得所选文件的完整路径>使用javascript,jquery-ajax?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!