How to display a photo of the database?

1

I can not display the photos I'm sending to the database. I am doing a comment system with photo and managed to send them to the database (mysql). I created my bank, then my table. I made the connection and all the items in the table are receiving their data. Only the photo that is not displayed when I call. Only the name of the photo with the extension appears. How can I view the photo with the other comment data? The error follows. In the first file I have the form and call in php of the comment. In the second file I get the data and send it to the database: I can call all the data, but the photo does not appear, just its name.

Form:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Classificdos</title>
</head>

<body>
  <div id="container">
    <h1>Faça seu Comentario</h1>

    <?php // aqui inicia a busca de comentarios dentro do banco de dados. require 'conexao.php'; $buscaComentario=m ysql_query( "SELECT * FROM comentarios WHERE identificacao = '1' AND moderacao ='nao'"); while ($lista=m ysql_fetch_array($buscaComentario))
    { $nome=$ lista[ 'nome']; $site=$ lista[ 'site']; $comentario=$ lista[ 'comentario']; $avatar=$ lista[ 'avatar']; echo "
                            <p><strong>NOME: </strong> $nome </p>
                            <p><strong>SITE: </strong> $site </p>
                            <p><strong>COMENTÁRIO: </strong> $comentario </p>
                            <img>$avatar</img>
                            <hr/>

                        "; } ?>
    <hr/>

    <h3>Deixe seu comentário</h3>

    <form id="" action="cadastraComentario.php" method="post" enctype="multipart/form-data">
      <fieldset>
        <legend>Preencha os Campos Abaixo:</legend>

        <label for="nome">NOME:</label>
        <input type="text" required id="nome" name="nome">
        <div class="clear"></div>

        <label for="email">E-MAIL:</label>
        <input type="text" id="email" name="email">
        <div class="clear"></div>

        <label for="site">SITE (Opcional):</label>
        <input type="text" id="site" name="site">
        <div class="clear"></div>
        <label for="comentario">Deixe seu Comentário</label>
        <br/>
        <textarea name="comentario" id="comentario" cols="60" rows="10"></textarea>

        <label id="escolher_foto" for="foto">Escolher uma Foto</label>
        <input type="file" name="avatar" id="avatar">

        <input type="submit" value="Comentar!">
        <br/>
        <input type="hidden" name="identificacao" value="1" />
        <input type="hidden" name="moderar" value="nao" />
      </fieldset>
    </form>

  </div>
</body>

</html>

sign up:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div id="seguraConteudo"> 

        <?php
        //error_reporting(0);

        require 'conexao.php';


        $nome =         $_POST['nome'];
        $email =        $_POST['email'];
        $site =         $_POST['site'];
        $comentario =   $_POST['comentario'];
        $identificacao= $_POST['identificacao'];
        $moderacao =    $_POST['moderar'];
        $arquivo =      $_FILES['avatar']['name'];
        $arquivoTemp =  $_FILES['avatar']['tmp_name'];

        $pasta = "imagens/";
// Coloca a foto em uma pasta diretorio
        move_uploaded_file($arquivoTemp, $pasta);


        $headers = "Content-type:text/html; charset=UTF-8";
        $headers = "From: $email";
        $para    = "[email protected]";
            $mensagem = "De: $nome";
            $mensagem .= "E-mail: $email";
            $mensagem .= "Site: $site";
            $mensagem .= "Comentario: $comentario";



        $envia = mail($para, "Comentário Efetuado no site", $mensagem, $headers);


        $insere = ("INSERT INTO comentarios (id, nome, email, site, comentario, identificacao, moderacao,avatar ) VALUES ('NULL', '$nome', '$email', '$site', '$comentario', '$identificacao', '$moderacao', '$arquivo')");

        $insereBanco = mysql_query($insere);

            echo "<p><strong>$nome</strong>, seu comentário foi efetuado com sucesso e aguarda liberação. Obrigado!";
            echo "<p><a href='Sistema_comentarios.php'>Voltar</a></p>";

        ?>
    </div>

</body>
</html>
    
asked by anonymous 26.02.2016 / 17:12

1 answer

1

From what I saw in your code, you're doing:

$avatar=$lista[ 'avatar'];

<img>$avatar</img>

As you are storing an image, the content of the $avatar variable is a url, so you should do so:

<img src=$avatar></img>

So I understand that.

Your problem is in the path tree for the images, in the database there is only one string which is the name and extension, thus an example of file organization:

This is the contents of the pastadomeuprojeto directory

-- index.html
-- pagina01.html
-- pagina02.html
-- /images
   -- logo.png
   -- decoracao.png
   -- frutas.jpg
-- /css
   -- home.css
-- /js
   -- effects.js

In general this is the file organization of a web project, if I am want frutas.jpg within my page page1.html, my url will be /images/frutas.jpg , if it does not it can be without the first bar / , if it still does not work use the full path:

C://../pastadomeuprojeto/images/frutas.jpg

    
26.02.2016 / 17:33