douyuan9512 2019-07-30 03:27
浏览 53

如何显示存储在数据库中的图像?

This is echo output of image I am storing an image as blob in a database as shown in the code below

        <?php

            // extract form values
        if(isset($_POST['submit']))
        {
        $empnum = $_POST['emp_num'];
        $lastname = $_POST['emp_lname'];
        $firstname  = $_POST['emp_fname'];
        $initial = $_POST['emp_initial'];
        $job = $_POST['job'];
        $username = $_POST['emp_usr'];
        $password = $_POST['emp_pass'];
        $emp_bdate = $_POST['emp_bdate'];

        $check = getimagesize($_FILES["image"]["tmp_name"]);
        if($check !== false){
            $image = $_FILES['image']['tmp_name'];
            $imgContent = addslashes(file_get_contents($image));

An insert for an employee details

// build query
            $qry = "INSERT INTO employee VALUES(" .
                "'$empnum','$lastname','$firstname'," .
                "'$initial','$job'," .
                "'$username',PASSWORD('$password'),' $emp_bdate',' $imgContent')";
            }
            // execute query
            $added = mysqli_query($dbconn,$qry);

This is to check if there is any error

    // report results
        if(trim($added) != "")  
echo  "Record added successfully." . "<br>";
        else
        {
            echo "ERROR: Record could not be added<br>" . 
                 mysqli_error($dbconn);
        }

        // close connection
        mysqli_close($dbconn);

    }
    ?>

I am outputting am image as below though no image displayed

        $imageData =base64_encode($line['image']); 
    echo "<img src='data:image/jpeg;base64,$imageData' height='200' width='250' alt=''>'"





  • 写回答

2条回答 默认 最新

  • dqzow3859 2019-07-30 03:31
    关注

    Don't save image file as base64, you just save where image dir place. So when you call image just call the url to image dir place.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端