How to display image stored in blob type [duplicate]

0

I have a database that has a blob field. This field is for a photo. I need to call this photo and show it. Home I do not own the photos that gave rise to the contents of the database, so it is not feasible to work linking the address. I know it's not good practice, but it's what I have. When I give echo to display the contents of what is saved in the blob field it returns something like 0x00000001000000a7 . I need to transform these numbers into an image and display it as if it were a <img> of the html. I've been browsing and I've seen the case Slideshow with MySQL BLOB images but I do not know why it does not work for me.

    
asked by anonymous 24.09.2017 / 00:01

1 answer

0

Well one of the ways you can use it and this code here it takes the update and saves it in the folder of your application and names the photo with the id of the user after and just retrieve the photo of the folder and that's it. Very simple and functional code! anything is just talking

<?php
    session_start();

        $PHP_SELF = "";
        //Diretório aonde ficará os arquivos
        $dir = "./image/users/profile_photo/";

        //Extensões permitidas
        $ext = array("gif","jpg","png");

        //Quant. de campos do tipo FILE
        $campos = 6;

        //Formulário
        echo '<form method="post" action="'.$PHP_SELF.'" enctype="multipart/form-data">
      <input type="file" name="file[]">
        <br />
        <br />
        <br />
     <input type="submit" name="submit" value=" OK ">
     </form>';


    //Se for enviado
    if (isset($_POST['submit'])) {

    //Obtendo info. dos arquivos
    $f_name = $_FILES['file']['name'];
    $f_tmp = $_FILES['file']['tmp_name'];
    $f_type = $_FILES['file']['type'];


    //Contar arquivos enviados
    $cont=0;

    //Repetindo de acordo com a quantidade de campos FILE
    for($i=0;$i<$campos;$i++){

    //Pegando o nome
    $name = $_SESSION['usuarioID'];

    //Verificando se o campo contem arquivo
      if ( ($name!="") and (is_file($f_tmp[$i])) and (in_array(substr($name, -3),$ext)) ) {

        if ($cont==0) {
          echo "<b>Arquivo(s) enviados:
    </b>";
        }
          echo $name." - ";

          //Movendo arquivo's do upload
          $up = move_uploaded_file($f_tmp[$i], $dir.$name);

            //Status
            if ($up==true):
                echo  "<i>Enviado!</i>";
                  $cont++;
            else:
                echo "<i>Falhou!</i>";
            endif;

          echo "
    ";
      }

    }

    echo ($cont!=0) ? "<i>Total de arquivos enviados: </i>".$cont : "Nenhum arquivo foi enviado!";
    }
    ?>

yes it is possible to make the img tag receive the EX path:

<div class="perfil">
  <img src="/image/users/profile_photo/<?php session_start(); echo $_SESSION['usuarioID']; ?>.jpg">
  <img>
</div>
    
24.09.2017 / 01:28