Upload

Asked

Viewed 61 times

0

I’m doing a photo upload system and it bugged! When I add the first photo goes all right, but if I try to change the photo again it doesn’t do the standard action anymore...

Jsfiddle

<div id="exibirfoto"><img src="$row[foto]" id="exibirfoto2"><div id="exibirfoto3">ALTERAR FOTO</div></div>
<form action="uploadfoto.php" method="post" enctype="multipart/form-data" id="uploadfotoform">
<input name="uploadfoto" id="uploadfoto" type="file" />
</form>
<script>
$(document).ready(function(event) {
    var options = {
    success: function(data) 
    {
    alert(data);
    }
    };
$("#uploadfotoform").ajaxForm(options);
});

$("#exibirfoto3").click(function() {
$("#uploadfoto").click();
});

$("#uploadfoto").change(function() {
var file = $("#uploadfoto").get(0).files[0].name;
$("#uploadfotoform").submit();
$("#exibirfoto").html("<img src='" + file + "' id='exibirfoto2'><div id='exibirfoto3'>ALTERAR FOTO</div>");
});
</script>

1 answer

3

I managed to resolve by changing the path of the photo instead of changing the html...(antepenlast line)

$("#exibirfoto2").attr("src", file);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.