getting the file input value in jquery
i am building one module wherein user can post their data. i have few text field and one image which while uploading via the HTML input control needs to previewed.
My Approach:
the HTML part:
<div class="divClass" id="FirstAd">
<h4 align="center">
Advertisement 1</h4>
<div style="float: left; width:25%">
<img src="images.jpg" id="repl开发者_高级运维aceMe" width="100px" height="130px" /></div>
<div style="float: right; width:70%; left:30%">
<input type="text" style="width: 197px" /><br />
<br />
<textarea class="AdContent"></textarea><br />
<br />
<input type="file" id="myImage" size="30" onchange="pictureUpload()" /><br />
<input type="button" value="Preview!"/><br/>
</div>
</div>
the j Query part:
function pictureUpload() {
$(document).ready(function() {
var imagepath = "file:\\" + $("#myImage").val();
$("#replaceMe").attr("src", imagepath);
alert(imagepath);
});
}
Am able to just get the filename with the extension not the path.
is there any alternative?? or some jquery plugin?? or can we retrieve the path inside a hidden field, since it is a security measure to prevent retrieving path from the file input ??
You can't do this. The input type="file"
has security around it so that you can't directly access the file from JavaScript.
it can be done by this way there is post in stack overflow by
by Ivan--thanks Ivan
精彩评论