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 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)