如何获得文件的完整路径,同时选择文件使用<input type= ' file ' >
<input type="file" id="fileUpload">
<script type="text/javascript">
function getFilePath(){
$('input[type=file]').change(function () {
var filePath=$('#fileUpload').val();
});
}
</script>
但是filePath var只包含所选文件的名称,而不是完整的路径。
我在网上搜索了一下,但似乎出于安全原因,浏览器(FF,chrome)只给出了文件的名称。
是否有其他方法获得所选文件的完整路径?
你不能这样做——出于安全考虑,浏览器不允许这样做。
When a file is selected by using the input type=file object, the value
of the value property depends on the value of the "Include local
directory path when uploading files to a server" security setting for
the security zone used to display the Web page containing the input
object.
The fully qualified filename of the selected file is returned only
when this setting is enabled. When the setting is disabled, Internet
Explorer 8 replaces the local drive and directory path with the string
C:\fakepath\ in order to prevent inappropriate information disclosure.
和其他
你错过了);这是在change事件函数的末尾。
也不要为change事件创建函数,而是像下面这样使用它,
<script type="text/javascript">
$(function()
{
$('#fileUpload').on('change',function ()
{
var filePath = $(this).val();
console.log(filePath);
});
});
</script>
你不能这样做——出于安全考虑,浏览器不允许这样做。
When a file is selected by using the input type=file object, the value
of the value property depends on the value of the "Include local
directory path when uploading files to a server" security setting for
the security zone used to display the Web page containing the input
object.
The fully qualified filename of the selected file is returned only
when this setting is enabled. When the setting is disabled, Internet
Explorer 8 replaces the local drive and directory path with the string
C:\fakepath\ in order to prevent inappropriate information disclosure.
和其他
你错过了);这是在change事件函数的末尾。
也不要为change事件创建函数,而是像下面这样使用它,
<script type="text/javascript">
$(function()
{
$('#fileUpload').on('change',function ()
{
var filePath = $(this).val();
console.log(filePath);
});
});
</script>