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

时间:2015-09-21 05:18:22

标签: php mysql

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

submit.php

public class MainActivity extends AppCompatActivity {
NotificationManager nm;
private static final int IDNOTIFICACIONUNO = 1;
Notification notif;

 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnLanzar = (Button) findViewById(R.id.boton_notificacion);

btnLanzar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
 Intent i = new Intent(getApplicationContext(),segundaVentana.class);
 PendingIntent intencionPendiente =  PendingIntent.getActivity(getApplicationContext(),0,i,0); 

 Notification.Builder notif = new Notification.Builder(getApplicationContext());

notif.setSmallIcon(R.drawable.tree);
notif.setTicker("App Nature ¡TIP!");
notif.setWhen(System.currentTimeMillis()); 
notif.setContentTitle("App Nature ¡TIP!");
notif.setContentText("Cierra la llave, cuando te estes cepillando");
notif.setContentInfo("TIP");
notif.setContentIntent(intencionPendiente);

 nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);             
 nm.notify(IDNOTIFICACIONUNO,notif);

 }


});
 }

并且

 <?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);
     ?>

2 个答案:

答案 0 :(得分:3)

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

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

答案 1 :(得分:-1)

在img src中指定上传图片路径,如下所示

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