Is it possible to get the image path from where it is selected in jquery before upload to a particular folder.
1 Answer
Try utilizing change event , URL.createObjectURL with this.files[0] as argument
$("input[type=file]").on("change", function() {
$("[for=file]").html(this.files[0].name);
$("#preview").attr("src", URL.createObjectURL(this.files[0]));
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<input id="file" type="file" accepts="image/*" /><br />
<label for="file"></label><br />
<img id="preview" />
2 Comments
Neethu
First of all thanks for your support.Here I need to display multiple images also.I have the below code for displaying images in dynamically generated div.div = $('<div class="photoclass" />'); img = $('<img />', { 'src': URL.createObjectURL(this.files[0]) }).prependTo(div); div.appendTo('.photo_inner'); Any idea please help?
guest271314
@Neethu "need to display multiple images also." Not appear at original Question ? See stackoverflow.com/help/how-to-ask . Tried using a loop for each
this.files ? See also stackoverflow.com/questions/28856729/…
namehtml,jsat Question ?