Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从数据库检索base64图像_Php_Mysql_Base64 - Fatal编程技术网

Php 从数据库检索base64图像

Php 从数据库检索base64图像,php,mysql,base64,Php,Mysql,Base64,我创建了一个简单的表,并以base64作为文本存储了一个图像, 当我试图从数据库中获取所有数据时,它工作得很好,除了图像显示在网站上,如下面的代码所示 LzlqLzRBQVFTa1pKUmdBQkFRQUFBUUFCQUFELzJ3QkRBQkFMREE0TUNoQU9EUTRT ..etc php代码 <!DOCTYPE html> <html> <head> <meta charset = "utf-8"> <titl

我创建了一个简单的表,并以base64作为文本存储了一个图像, 当我试图从数据库中获取所有数据时,它工作得很好,除了图像显示在网站上,如下面的代码所示

LzlqLzRBQVFTa1pKUmdBQkFRQUFBUUFCQUFELzJ3QkRBQkFMREE0TUNoQU9EUTRT ..etc
php代码

<!DOCTYPE html>
<html>

<head>
    <meta charset = "utf-8">
    <title> Welcome </title>
    <script> </script>
    <style></style>
</head>
    <body>
        <table border = "solid">
            <tr>
                <th> id </th>
                <th> Millitary number </th>
                <th> Fname </th>
                <th> Lname </th>
                <th> Image </th>
            </tr>
            <?php 
                $conn = mysqli_connect("localhost" , "id2549459_salamnti" , "0000000000" , "id2549459_tutorial");
                if($conn -> connect_error){
                    die("my connection faild" . $conn -> connect_error);
                }

                $sql = "SELECT id, militry_num , firstname, lastname,image from students";
                $result = $conn-> query($sql);
                if($result -> num_rows > 0){
                    while($row = $result-> fetch_assoc()){
                        echo "<tr> <td>" . $row["id"] .  "</td> <td>"
                            . $row["militry_num"] . 
                             "</td> <td>". $row["firstname"] .
                             "</td><td>" . $row["lastname"] . "</td><td>" .
                             base64_encode($row["image"]) . 
                             "</td> </tr>";
                }
                    echo "</table>";
                }
                else{
                echo "0 result" . $conn->error;
                    }
                        $conn -> close();
            ?>
        </table>
    </body>
</html>

欢迎
身份证件
军号
Fname
名字
形象

任何解决方案如何显示我当前问题的db中的图像?

数据:image/gif;base64



欢迎
身份证件
军号
Fname
名字
形象

您可能需要
base64\u decode
而不是,尽管我认为您可能需要更多的东西…您将图像以blob类型存储在数据库中。当您使用
base64\u encode($row[“image”])
进行输出时,您是双重编码。然而,像我认为您正在尝试的那样将图像放入html中,并不是这样做的。您需要按照以下思路做一些事情:我需要检索数据库中的所有行,以及图像,这样我可以如何修改我的代码。?它工作得很好,谢谢您,但有些图像显示大,有些图像显示小,我可以确定在我的html网站上显示的图像的高度和宽度吗???
 <img src="data:image/gif;base64,' . $row["image"] . '" />
<head>
<meta charset = "utf-8">
<title> Welcome </title>
<script> </script>
<style></style>
</head>
<body>
    <table border = "solid">
        <tr>
            <th> id </th>
            <th> Millitary number </th>
            <th> Fname </th>
            <th> Lname </th>
            <th> Image </th>
        </tr>
        <?php 
           $conn = mysqli_connect("localhost" , "id2549459_salamnti" , "0000000000" , "id2549459_tutorial");
            if($conn->connect_error){
                die("my connection faild" . $conn->connect_error);
            }

            $sql = "SELECT id, militry_num , firstname, lastname,image from students";
            $result = $conn->query($sql);
            if($result->num_rows > 0){
                while($row = $result->fetch_assoc()){
                    echo "<tr> <td>" . $row["id"] .  "</td> <td>"
                        . $row["militry_num"] . 
                         "</td> <td>". $row["firstname"] .
                         "</td><td>" . $row["lastname"] . "</td><td>" .
                         '<img src="data:image/gif;base64,' . $row["image"] . '" />' . 
                         "</td> </tr>";
            }
                echo "</table>";
            }
            else{
            echo "0 result" . $conn->error;
                }
              $conn->close();
        ?>
    </table>
</body>