php - 在 PHP 中显示和检索数据库中的图像

标签 php mysql

我想显示来自数据库的图像,但目前它只显示图像的名称。需要帮忙。这是我的代码

提交.php

 <?php
     $radio  = $_POST['RadioGroup1'];

     $img_banner = $_FILES['bannerImage']['name'];
     $target_file = "uploads/";

     if(!empty($img_banner))
     {
      $errors = array();
      $file_name = $_FILES['bannerImage']['name'];
      $file_size = $_FILES['bannerImage']['size'];
      $file_tmp = $_FILES['bannerImage']['tmp_name'];
      $file_type = $_FILES['bannerImage']['type'];
      $file_ext = strtolower(end(explode('.',$_FILES['bannerImage']['name'])));
      $k  =  move_uploaded_file($file_tmp,"uploads/".$file_name);

    }

    $date = $_POST['date'];

    $qry_banner = "INSERT INTO `banner_tbl`(`banner_img`, `date`) VALUES  ('$img_banner','$date')";
    $res_banner = mysql_query($qry_banner);
    $banner_tbl_id = mysql_insert_id();


    $sec_id = $_POST['sectionID'];
    $sec_active_image = $_POST['activeimage'];
    $sec_title = $_POST['section_title'];


      $total_sec = count($sec_id);

     for($i=0;$i<$total_sec;$i++)
     {
      $qry_section1 = "INSERT INTO `section_lt_tbl`(`banner_id`, `sectionID`,    `activeimage`, `sectiontitle`) VALUES 
     ('$banner_tbl_id','$sec_id[$i]','$sec_active_image[$i]','$sec_title[$i]')";

     $res_section1 = mysql_query($qry_section1); 
    $sec_tbl_id1 = mysql_insert_id();

    $section_generated_id[] = $sec_tbl_id1;

    }

    $array_section_ids = array();
    for($i=1;$i<=$radio;$i++)
    {
     $j = $i-1 ;    
    $array_section_ids[$i] = $section_generated_id[$j];

    }

      for($h=1;$h<=count($array_section_ids);$h++) 
       {
       $news_ids_sec[$h] = $_POST['sec_'.$h.'_new'];
       $news_title_sec[$h] = $_POST['sec_'.$h.'_title_news'];
       $sec_1_desc[$h] = $_POST['sec_'.$h.'_desc'];
       $sec_1_newslink[$h] = $_POST['sec_'.$h.'_newslink'];
       $sec_1_news_url[$h] = $_POST['sec_'.$h.'_news_url'];
       $sec_1_news_img[$h] = $_FILES['sec_'.$h.'_news_img']['name'];
       $temp_file[$h] = $_FILES['sec_'.$h.'_news_img']['tmp_name'];

       $section  = $array_section_ids[$h];


       for($c=0;$c<count($news_ids_sec[$h]);$c++)
       {
        $id =  $news_ids_sec[$h][$c];
    //  $sec_id =  $array_section_ids[$h][$c];
        $title=  $news_title_sec[$h][$c];
        $desc =  $sec_1_desc[$h][$c];
        $link =  $sec_1_newslink[$h][$c];
        $url = $sec_1_news_url[$h][$c];
        $img =  $sec_1_news_img[$h][$c][0];
        $tmp_name = $temp_file[$h][$c][0];


        $qry_news_insert = "INSERT INTO `news_lt_tbl`(`newsid`, `news_sec_id`,     `newstitle`, `Description`, `titleoflink`, `urlofnews`, `news_img`) VALUES     ('$id','$section','$title','$desc','$link','$url','$img')";

         $res_news = mysql_query($qry_news_insert);

         $file_name = $img;
         $file_tmp = $tmp_name;
         $file_ext = strtolower(end(explode('.',$file_name)));
         $k  =  move_uploaded_file($file_tmp,"uploads/".$file_name);
       }
      }
      ?>
     <?php

       $qry_test = "SELECT * FROM `section_lt_tbl` WHERE sec_id = 162";

       $res_tses = mysql_query($qry_test);
       $arr = mysql_fetch_assoc($res_tses);
      ?>
      <?php
      $query = "SELECT `newsid`, `newstitle`, `Description`, `titleoflink`,     `urlofnews`, `news_img` FROM `news_lt_tbl` ";
      $result_news = mysql_query($query);
      $file_name = $img;
      $file_tmp = $tmp_name;
      $file_ext = strtolower(end(explode('.',$file_name)));
      $k  =  move_uploaded_file($file_tmp,"uploads/".$file_name);
     ?>

      <table align="center" width="600"> 
           <tr>
           <tr>
           <td bgcolor="#ffffff" valign="bottom" align="left"><a href="http://nrsadvisors.com/"><img border="0" src="http://www.nrsadvisors.com/email-images/mainlogo.jpg" alt="NRS Advisors"/></a></td>
           </tr>
           <tr>
                <td style="border-top-width:2px; border-top-style:solid; border-top-color: #3E7DBD;" bgcolor="#dbdbdb"><img border="0"  src="http://www.nrsadvisors.com/email-images/banner-hero-image.png" alt="bannerimg" width="550" /><a name="featuredstartup" style="height:0;margin:0;padding:0"></a></td>
              </tr>
           <td bgcolor="#dbdbdb" align="center"><table border="0" cellpadding="0" cellspacing="0" width="550" align="center">
           <tr>

           <td width="25%"><a href="#featuredstartup"><img src="uploads/<?php     echo $arr['activeimage'] ?>_blue.jpg" width="125px" height="134px" />
</a></td>
           <td width="25%"><a href="#healthcaredeals"><img src="uploads/<?php       echo $arr['activeimage'] ?>_grey.jpg" width="125px" height="134px" /></a></td>
           <td width="25%"><a href="#healthcarenews"><img src="uploads/<?php     echo $arr['activeimage'] ?>_grey.jpg" width="125px" height="134px" /></a></td>
           <td width="25%"><a href="#healthcaremarkets"><img src="uploads/<?php     echo $arr['activeimage'] ?>_grey.jpg" width="125px" height="134px" /></a></td>

           </tr>
           </table>
           </td>
           </tr>

            <?php   
                while ($row = mysql_fetch_array($result_news)) {
           ?>
           <table align="center" width="600"> 
           <tr>

           <span style="font-size:14px;line-height:17px;font-weight:normal;color:#333333">
           <td align="left">
           <span style="font-weight:bold">
           <?php echo $row['newsid'] ?>
           </span>
           </td>
           </span>
           </tr>
           <tr>
           <td>
            <span align='left' style='color:#3E7DBD;font-weight:bold'>
            <span style='font-size:14px;line-height:17px;font-weight:normal;color:#333333'><span style='font-weight:bold'>
            <?php echo $row['newstitle'] ?>
            -</span><br><br>
            </td>
            </tr>
            <tr>
            <td><?php echo $row['Description'] ?></td><br><br>
            </tr>          
            <tr>
            <td>
            <a href="<?php echo $row['urlofnews'] ?>" style='font-size:14px;line-height:17px;color:#3FC47B; text-decoration:none;'><?php echo $row['titleoflink'] ?></a></td><br><br>
            </tr>
            <tr>
            <td><?php echo $row['news_img'] ?></td>
            </tr>
            </table>

      <?php
             }
        ?>

最佳答案

您需要使用img 标签来显示图片。像这样:

 <img src="your_upload_path/<?php echo $row['news_img'] ?>" />

关于php - 在 PHP 中显示和检索数据库中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32687852/

相关文章:

php - 使用 group by 函数对多列进行 sum()

mySQL 子查询

java - 在 MySQL 中使用印度数字分隔符格式化货币金额

mysql - 格式化数据以在 CakePHP 3.4 中保存和显示

php - MYSQL 按最近的 UTM 坐标对结果进行排序

mysql 返回所有行,无论数据存在与否

php - Zend InputFilter 需要国际 PHP 扩展吗?

javascript - 动态坐标谷歌地图无法加载

php - 将数组转换为独立的函数参数 - 如何?

php - 将 mysql 中的数据从 1252 转换并显示为 UTF-8