I'm making a website for sales (personal thing, just training) and my problem happens with displaying the uploaded image of the DB. The browser identifies that it has an image there, but it does not display it.
Sending the image by $_FILES
in HTML
<html>
<head>
<title></title>
<meta charset="utf-8/">
</head>
<body>
<form name="enviaImg" action="salvaImg.php" method="POST" enctype="multipart/form-data">
<input type="file" name="imagem" value=""/>
<p>Categoria: <input type="text" name="eCategProd"/></p>
<p>Descricao: <input type="text" name="eDescricao"/></p>
<p>Preco: <input type="text" name="ePreco"/></p>
<input type="submit" name="envia" value="Salvar"/>
</form>
</body>
</html>
saved image in PHP with $_FILES
:
<?php
$nomeProd = $_FILES["imagem"]["name"];
$temp = $_FILES["imagem"]["tmp_name"];
$categProd = $_POST["eCategProd"];
$precoProd = $_POST["ePreco"];
$descProd = $_POST["eDescricao"];
$conexao = mysqli_connect('localhost', 'root', '', 'ecomoveis');
$insere = mysqli_query($conexao, "INSERT INTO tb_produto (prod_Nome, prod_Descricao, prod_Categoria, prod_Url, prod_Preco) VALUES ('{$nomeProd}', '{$descProd}', '{$categProd}', '{$temp}', '{$precoProd}')") or die(mysqli_error($conexao));
move_uploaded_file($temp, "../EcoMoveis/Moveis/".$nomeProd);
header("location: enviar.php");
?>
I read and organize in a vector and display on another page PHP:
<?php
$conexao = mysqli_connect('localhost', 'root', '', 'ecomoveis');
$consulta = mysqli_query($conexao, "SELECT * FROM tb_produto WHERE prod_Categoria = 'Cadeira'");
while($linha = mysqli_fetch_array($consulta))
{
$produto[] = $linha;
}
?>
And finally display in any field within <body>
<html>
<body>
<div class="produto-imagem">
<?php
include("../PHP/Cadastro de Produtos/pegaImg.php");
foreach($produto as $prod)
{
?>
<img src="<?php echo "../EcoMoveis/Moveis/".$prod["prod_Nome"] ?>"/>
<?php
}
?>
</div>
</body>
</html>
In case there are 2 images with the category "Chair", then it places 2 squares (same as those that appear when you do not recognize the image) but nothing of the image appears