Uploading photos

0

I'm doing a photo upload system and it bugou! When I add the first photo it will be fine, but if I try to change the photo again it does not do the default 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>
    
asked by anonymous 28.08.2014 / 16:56

1 answer

3

I could solve by changing the path of the photo instead of changing the html ... (penultimate line)

$("#exibirfoto2").attr("src", file);
    
28.08.2014 / 17:07