php - 以 html 形式从数据库获取图像后不显示

标签 php mysql html

在我的页面中,它没有显示图像/..在图像中,它显示空白框 我不知道我哪里错了..

   <form action="login.php" method="post" enctype="multipart/form-data">
   <input type="text"
    <br><br><br>
    select image:<input type="file" name="image" size="40" id="image">
              <br><small> must be less than 512kb </small>

    <br><br>         <input type="submit" name="submit" value="submit">  
    </form>

即使我没有发现任何错误...请纠正我并告诉我为什么它没有显示任何图像

   <?php

 if(isset($_POST['submit']))
 {
 if(getimagesize($_FILES['image'] ['tmp_name'])==FALSE)

{ 
    echo "<script> please insert the image </script>";
     exit();
 }

 else
 {
 $image=addslashes($_FILES['image'] ['tmp_name']);
 $name=addslashes($_FILES['image'] ['name']);
 $image= file_get_contents($image);
 $image= base64_encode($image);
 saveimage($name,$image);


 }
}

  displayimage();

  function saveimage($name,$image)
  {
   $con=@mysqli_connect("localhost","root","","work");

   $qry="insert into pics( name, image) values('$name','$image')";

    $result= mysqli_query($con,$qry);

if($result)
{
echo"<br> image uploaded";
}

else
  {
   echo"<br> image not uploaded";
   }

   }

function displayimage()
{
  $con=@mysqli_connect("localhost","root","","work");

  $qry= "select* from pics";

  $result= mysqli_query($con,$qry);

   while($row = mysqli_fetch_array($result))
 {
    echo"<img height=\"250\" width=\"250\" src=\"data:image;base64,\" '.$row[2].' >";
  }
  mysqli_close($con);


 }


 ?>

我被困在这里,请帮助我离开这里

最佳答案

也许这有帮助: How to display Base64 images in HTML?

您能否向我们提供生成的 html?

也许您必须提供文件类型,jpg/png:

关于php - 以 html 形式从数据库获取图像后不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31804376/

相关文章:

php - 在 mysql 数据库中存储帖子 + 评论

javascript - Iframe 内容窗口

java - 来自 <c :forTokens> 的标记串联

php - mysql_real_escape_string - 访问被拒绝,取决于执行脚本的用户?

php - 这是一个 php 错误 : subclasses must declare private methods with the same signature as in parent class

mysql - 读取 row = mysql_fetch_row(result) 返回的 mySQL 数据库的行集,这是一个字符串数组,用于从中提取各个字段

html - MySQL 到 InnerHtml Angular 7

mysql - 子查询的替代优化查询

c# - 如何在允许 HTML 输入的同时防止 XSS(跨站点脚本)

无论如何,PHP 是否可以执行此 javascript 技巧?