php - 基本的64位代码不起作用…无法以html php mysql形式显示数据库中的图像-LMLPHP

php - 基本的64位代码不起作用…无法以html php mysql形式显示数据库中的图像-LMLPHP

图1st显示了我的屏幕,并显示了数据库外观

     <form action="login.php" method="post" enctype="multipart/form-data">

  <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))
    {
      $img_type = 'png or jpg';
      echo"<img height='250' width='250' src='data:image/".$img_type.";base64', '".$row[1]."' >";
     }
    mysqli_close($con);


    }


     ?>


不知道该怎么办..请帮助我

最佳答案

echo "<img height='250' width='250' src='data:image/" . $img_type . ";base64," . $row[1] . "' >";


尝试将其替换为@showdev建议的代码

关于php - 基本的64位代码不起作用…无法以html php mysql形式显示数据库中的图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31815043/

10-12 12:52
查看更多