dongyata3336 2013-12-02 08:52
浏览 46
已采纳

从mysql php获取图像

here i am trying to upload the employee profile picture to mysql and then i want to fetch those picture. now i can uploaded the image into mysql db successfully but, when i try to fetch the image that doesn't fetch properly. if you open an image in texteditor na how it will look like? the same thing i got it now.. like this... (QÕf0±Ó%"÷YúEûVÚo¾e9°R}È"!5®?•Ÿ\¯ž›ÃÕîYU0T³¼´œ\aVë%z€ÙBðŒÆnPÈ Qx•eú0´ÁPÁ”·=ó-)Oyá+×½ÄS„ÞšÅS!Y¨;,¾¤ª5HÅÓôÍó3Áº¶j/"5±•RX›ee.&{ +C˜ H CÌai,F+Ô#”?Ì8««IÐO%IW).

my question is how to fetch the image properly? and then is there any other way to do store an image to mysql db. for example save a employee profile pictures to one folder and then store that link to mysql???

index.php code:

<form enctype="multipart/form-data" action="img.php" method="post" name="changer">
<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
</form>
<?php
include("config.php");
$query = mysql_query("SELECT * FROM tbl_images");
while($row = mysql_fetch_array($query))
{
    echo "" . $row['image'] . "";
}
?>

img.php code:

<?
include("config.php");
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

  $tmpName  = $_FILES['image']['tmp_name'];  

  $fp      = fopen($tmpName, 'r');
  $data = fread($fp, filesize($tmpName));
  $data = addslashes($data);
  fclose($fp);

  $query = "INSERT INTO tbl_images ";
  $query .= "(image) VALUES ('$data')";
  $results = mysql_query($query, $link) or die(mysql_error());

  print "Thank you, your file has been uploaded.";

  }
  else {
  print "No image selected/uploaded";
  }
?>
  • 写回答

5条回答 默认 最新

  • dongquexi1990 2013-12-02 08:55
    关注

    Can you try this,

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

    Your code:

    while($row = mysql_fetch_array($query))
    {
       echo '<img src="data:image/png;base64,' . base64_encode($row['image']) . '" />';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法