0

Is it possible to get the image path from where it is selected in jquery before upload to a particular folder.

tereško
  • 58,060
  • 25
  • 98
  • 150
Neethu
  • 85
  • 4
  • 9

1 Answers1

1

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" />
guest271314
  • 1
  • 15
  • 104
  • 177
  • 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 = $('
    '); img = $('', { 'src': URL.createObjectURL(this.files[0]) }).prependTo(div); div.appendTo('.photo_inner'); Any idea please help?
    – Neethu Sep 10 '15 at 06:28
  • @Neethu _"need to display multiple images also."_ Not appear at original Question ? See http://stackoverflow.com/help/how-to-ask . Tried using a loop for each `this.files` ? See also http://stackoverflow.com/questions/28856729/upload-multiple-image-using-ajax-php-and-jquery/ – guest271314 Sep 10 '15 at 06:35