dongnao3990 2014-04-17 10:46
浏览 180

无法使用base64_encode显示blob图像

I'm having problem with displaying image which is stored in a database as a blob. In localhost it works perfect, but on the server it doesn't show anything. Could someone help me please. I've already surfed the internet to find the answer, and read many forums but still couldn't find the answer.

Here is my code.

<form action="index.php" method="POST" enctype="multipart/form-data">
                  File:
                  <input type="file" name="image"> <input type="submit" value="upload">
                </form>

                <?php 
                $file = $_FILES['image']['tmp_name'];

                if(!isset($file))
                  echo "Please select some image";

                else 
                {
                  $tmpImageName=$_FILES['image']['tmp_name'];
                  $image_name = addslashes($_FILES['image']['name']);
                  $image_size = getimagesize($_FILES['image']['tmp_name']);
                  $handle      = fopen( $tmpImageName, 'r' );
                  $content = fread( $handle, filesize( $tmpImageName ) );
                  fclose($handle);

                  if($image_size==FALSE)
                    echo "That's not an image";

                  else 
                  {

                    $sql="insert into image values ('','$image_name','".mysql_real_escape_string($content)."')";

                    mysql_query($sql) or die(mysql_error());


                    $res = mysql_query("SELECT * FROM image "); 
                    while ($row = mysql_fetch_assoc($res)) 
                    {
                      echo "<img src=data:image/jpeg;base64," . (base64_encode(($row['Image']))) . " width=60px height=60px>";
                    }
                  }

                }

                ?>
  • 写回答

1条回答 默认 最新

  • douxing9641 2014-05-08 06:06
    关注

    try

     echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image']) .' "/>';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了