2013-08-17 31 views
0

我想要使用输入标记访问从浏览文件获得的文件路径。我想显示路径。如何在JavaScript中的文件输入标记的路径

+0

呃,darn,点击了错误的重复链接,但是这是重复的[如何使用javascript]改变选择文件的完整路径(http://stackoverflow.com/问题/ 15201071 /如何获取所选文件的全路径选择文件-jav) – FakeRainBrigand

+0

可能的重复[如何将文件的路径写入在文本框中上传?](http://stackoverflow.com/questions/4640082/how-to-write-the-path-of-a-file-to-upload-in-a-text-box) –

+0

可能我可以使用任何HTML或JavaScript API来获取输入\ [type = file \]中的文件路径吗?](http://stackoverflow.com/questions/10084133/can-i-use-any-html-或-javascript-api-to-get-the-files-path-in-inputtype-file) –

回答

0

下面是一个例子使用jquery:

<input type="file" id="input" /> 

$(document).ready(function() { 
    $("#input").on("change", function() { 
     alert($(this).val()); 
    }); 
}); 

即$(this).val()包含文件路径。

这里是一个的jsfiddle例如http://jsfiddle.net/krasimir/uwaf2/

0

Use jQuery to get the file input's selected filename without the path

$('input[type=file]').val() 
var filename = $('input[type=file]').val().split('\\').pop(); 

,或者你可能只是这样做(因为它总是C:\被添加 为fakepath安全原因):

var filename = $('input[type=file]').val().replace(/C:\\fakepath\\/i, '') 

Full path from file input using jQuery

不能读取由于安全原因,在JS完整的文件路径。

+0

在Windows以外的平台上它是“C:\ fakepath \”吗?在Linux或Mac上看到这条路,我感到很奇怪。 – fredden

相关问题