简体   繁体   English

从数据库插入图像(BLOB)Echo

[英]Insert image from database (BLOB) Echo

I am trying to insert a image which belongs to an employee profile. 我正在尝试插入属于员工档案的图像。

My code: 我的代码:

<?php
    $sql = "SELECT * FROM employeeTbl where department='aarhus';";
    $rows=$conn->query($sql);
    foreach ($rows as $row){
        echo '<div class="col-xs-6 col-sm-3" style="min-height:225px;overflow:hidden; margin-top:30px">;
?>

<img src="getimage.php?aid=<?php echo $row["aid"]; ?>" />

<?php
        echo '<h2 style="margin-top:-10px">'.$row["name"].'</h2>';
        echo '<i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;<a href="mailto:'.$row["mail"].'">' .$row["mail"].'</a>';      
        echo "</div>";
    }
?>

My getimage.php code is: 我的getimage.php代码是:

<?php
     $conn = mysql_connect("mysql34.unoeuro.com", "user", "pass");
     mysql_select_db("dbname") or die(mysql_error());

     if(isset($_GET['aid'])) {
          $sql = "SELECT image FROM employeeTbl WHERE aid=" . $_GET['aid'];
          $result = mysql_query("$sql") or die("<b>Error:</b> Problem on Retrieving Image BLOB<br/>" . mysql_error());
          $row = mysql_fetch_array($result);
          header('Content-Type: image/jpeg');
          echo $image;
     }
     mysql_close($conn);
?> 

My database the aid is Auto increment. 我的数据库援助是自动增量。

Hope you can help me - or find a better solution to this. 希望你能帮助我 - 或者找到更好的解决方案。

In the first step mysql is deprecated and i suggest using to mysqli functions. 在第一步中,不推荐使用mysql,我建议使用mysqli函数。

About creating image i suggest following code: 关于创建图像我建议以下代码:

$data = base64_decode($image);
$im = imagecreatefromstring($data);
if ($im !== false) {
     header('Content-Type: image/png');
     imagepng($im);
     imagedestroy($im);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM