0
I have a registration form where between the fields has a file field. It registers normally.
<div class="form-group">
<label for="foto">Foto do(a) Vereador(a):</label>
<input type="file" name="Foto" class="form-control" id="fileUpload" placeholder="Foto do Vereador(a)">
<img id="imagem" src="#" alt="Preview da sua imagem" style="width: 130px; margin-top: 10px; display: none" class="img-thumbnail" />
<label id="excluir" style="margin-left: 50px; color: #00F; display: none; cursor: pointer">Excluir</label>
</div>
Jquery
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$("#imagem").attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#fileUpload").change(function(){
readURL(this);
$("#imagem").css("display","block");
$("#excluir").css("display","block");
});
$("#excluir").click(function(){
$("#fileUpload").val("");
$("#imagem").css("display","none");
$("#excluir").css("display","none");
});
All right, all right! The only problem is when I try to bring this field into user editing. At the time of bringing the results of the database to the issue I am doing so:
<div class="form-group">
<label for="foto">Foto do(a) Vereador(a):</label>
<input type="file" name="Foto" class="form-control" id="fileUpload" value="<?php echo $visualizar->FotoUsuario; ?>">
<img id="imagem" src="<?php echo "../../fotos/".$visualizar->FotoUsuario; ?>" alt="Preview da sua imagem" style="width: 130px; margin-top: 10px;" class="img-thumbnail" /><br>
<label id="excluir" style="margin-left: 50px; color: #00F; cursor: pointer">Excluir</label>
</div>
The problem is when I click on the Delete link:
It is not deleting the value from the file field. Jquery is the same as the one I passed above.
Hi Lucas. It didn’t work. The image name remains in the value of the file field.
– user24136
Use removeAttr, try now
– Lucas de Carvalho
Thank you Lucas.
– user24136