Boa tarde, preciso de ajuda…
Estou tentando visualizar a imagem na pagina antes do Upload.
Aparece a imagem em branco…
O caminho fica C:\fakepath\imagem.jpg
function ativafigura2() {
document.getElementById('foto1').innerHTML = "<img border=\"0\" height=150px width=150px src=\""+document.formImagem.imagem1.value+"\" name=\"img\">"
largura = document.getElementById("img").width;
altura = document.getElementById("img").height;
if (largura > 350 || altura > 225 )
{alert("A imagem é "+largura+"x"+altura+" está fora do padrão requerido");
}
else
{
alert("O arquivo foi Aceito... \n Localização: "+document.formImagem.imagem1.value+"\n Bytes \n Dimensões :"+largura+"x"+altura)}
//alert("O arquivo foi Aceito... \n Localização: "+document.formImagem.imagem1.value+"\n Tamanho: "+tamanho_imagem+" Bytes \n Dimensões :"+largura+"x"+altura)}
}
<form id="formImagem" name="formImagem" method="post" action="ServletCadastroImovel" enctype="multipart/form-data">
<input type="hidden" id="textIdUser" name="textIdUser" value="<%=iduser%>">
<p>Nome : <input type="text" id="textNome" name="textNome" maxlength="30"> </p>
<p>E-mail : <input type="text" id="textEmail" name="textEmail" maxlength="20"> </p>
<p>Telefone : <input type="text" id="textTelefone" name="textTelefone" onkeypress='return SomenteNumero(event)' maxlength="10"> </p>
<p>Endereço : <input type="text" id="textEndereco" name="textEndereco"> </p>
<input type="hidden" id="tipoForm" name="tipoForm" value="imagem">
<table border=1 bordercolor="black">
<tr><td width="300" align="center"><div id="foto1" ></div></td></tr>
<tr><td width="300">
<input name="imagem1" type="file" onchange="ativafigura2()" accept="image/jpeg; image/gif; image/bmp; image/png" id="imagem1" class="dados" maxlength="40" tabindex="1" value="c:" style="width:500px;">
</td>
</tr>
</table>
<input type="button" type="submit" value="Inserir" id="upload" onclick="validaFormulario();" name="upload" tabindex="2" style="position:absolute; left:32px; ">
</form>