无法使用base64_encode显示blob图像

时间:2014-04-17 10:46:18

标签: php mysql blob

我遇到显示图像的问题,该图像作为blob存储在数据库中。在localhost中,它工作得很完美,但在服务器上却没有显示任何内容。请有人帮助我。我已经上网查找答案,阅读了很多论坛,但仍无法找到答案。

这是我的代码。

<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 个答案:

答案 0 :(得分:1)

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