如何获得图像的完整路径 [英] How do I get the full path of an image
本文介绍了如何获得图像的完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望单击选择文件按钮后显示所选图像的完整路径.关于如何做到这一点的任何想法?
I want the full path of a selected image to be displayed once Choose File button is clicked. Any idea on how to do that?
推荐答案
除了执行两次POST之外,您还可以执行以下操作:
Instead of doing a double POST, you can do something like this:
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function() {
readURL(this);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="form1" runat="server">
<input type='file' id="imgInp" />
<img id="blah" src="#" alt="your image" />
</form>
请记住,仅因为您选择了要上传的文件并不意味着该文件已上传.服务器仍然没有收到数据,因此,从客户端收集数据要比我想做的要有意义.
Remember, that just because you've selected a file to upload doesn't mean its been uploaded. The server still hasn't received the data, thus, doing this on the client side makes a little more sense from what i gather you want to do.
(从以下地址窃取:在上传图片之前预览图片)
这篇关于如何获得图像的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文