WHAT I'M DOING
I'm trying to implement profile picture changing in php/jquery. When an image is uploaded the preview of the image is shown.
WHAT I REQUIRE
I want to get the src of the previewed image. When i use $('img').attr('src');
it gives the src of the old image and not the new previewed image.
SCRIPT
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
var image = $('#img').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
HTML
<div class="pic">
<form id="form1" enctype="multipart/form-data">
<img src="profile.jpg" width="150" alt="profile" title="" id="img"/>
<span>Change Picture?</span>
<div class="up">
<input type='file' name ="file" id="imgInp" />
</div>
<input type="submit" name="picture" id="picture" value="Update"/>
</form>
</div>