How to view image stored in blob type

Asked

Viewed 1,361 times

0

I have a database that has a blob field. This field is to have a photo. I need to call this photo and display it.
I do not have the photos that originated the contents of the database, so it is impossible to work linking the address. I know it’s not good practice, but it’s what I have.
When I give a echo to display the contents of what is saved in the blob field it returns something like 0x00000001000000a7. I prescribe to turn these numbers into an image and display it as if it were a <img> of html.
I’ve been doing some research and I’ve seen the case Slideshow with Mysql BLOB Images but I don’t know why it doesn’t work on me.

  • The ideal would be for you to upload the file to a folder and save the name of the file that was uploaded to the database, and then, when displaying the image, select the file name.

  • The problem is I don’t have the images, only the database.

1 answer

0

Good one of the way you can use and this code here it takes the update and saves in the folder of your application and names the photo with the user id after and just recover the photo from the folder and done. Very simple and functional code! anything to say

<?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 and 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>
  • The problem is that I don’t have the images that gave "origin" to the database.

  • @Rafaelpessoa explain better the question I do not understand

  • I have a database with a blob field that refer to some photos, however I don’t have the photos in a separate file. Only what is in the database. I need to make these photos appear in a <img> field to make it similar to an identity.

  • $querry= $conexao_pdo->prepare("SELECT *FROM table "); $querry->execute(); $result = $querry->fetchAll(PDO::FETCH_ASSOC); foreach($querry as $result )' echo"<img src='/image/users/profile_photo/$result['campo_da_imagem'];'> <img>" } tries to follow this reasoning here @Rafaelpessoa

Browser other questions tagged

You are not signed in. Login or sign up in order to post.