0

I have a form that uploads a news article with it's picture and then stores all the info correctly. I am using codeigniter with Active Record and would like to know how to display the image with the post it was uploaded with.

here is my upload script:

    public function create(){
        $data = array('error' => '');
        $config = array(
                'upload_path' => './uploads',
                'allowed_types' => 'gif|jpg|png',
                'max_size' => '204800',
                'max_width' => '1920',
                'max_height' => '1080',
                'encrypt_name' => true
            );

        $this->load->library('upload', $config);

            if(!$this->upload->do_upload()) {
                $error = array('error' => $this->upload->display_errors());
                $data['title'] = 'Create a news item';
                $data['main_content'] = 'news/create';
                $this->load->view('templates/template', $data, $error);
            }

        else{
            $slug = url_title($this->input->post('title'), 'dash', TRUE);
            $upload_data = $this->upload->data();
            $data = array(
                'post_title' => $this->input->post('title'),
                'slug' => $slug,
                'post_text' => $this->input->post('body'),
                'post_date' => time(),
                'post_image' => $upload_data['file_name'],
                'post_date' => time()
            );

        $this->db->insert('news', $data);
        $data['title'] = 'News item has been published';
        $data['main_content'] = 'news/success';
        $this->load->view('templates/template', $data);
        }
    }

Section in the view that needs to output the data

       <?php if(count($news) > 0){?>
      <?php foreach ($news as $news_item): ?>
       <h3 id="news_feed_title"><?php echo $news_item['post_title'] ?></h3>
         <img src="<?php echo $news_item['post_image'] ?>" class="img-responsive">
         <p class="news_feed_text"><?php echo character_limiter($news_item['post_text'], 250);?>&nbsp;
         <a href="news/<?php echo $news_item['slug'] ?>" class="anchor">Read Article &nbsp;<i class="fa fa-eye"></i></a>
          </p>
          <p>
          <?php echo "<hr>"; ?></p>
          <?php endforeach; ?>
          <?php }else{ ?>
          That's strange, no news items were found.
          <?php } ?>

How do i display the image?

2
Contributors
2
Replies
27
Views
2 Years
Discussion Span
Last Post by mateo2181
1

Solution was

<img src="<?php echo base_url().'uploads/'.$news_item['post_image'] ?>" class="img-responsive">
1

<img src="<?php echo base_url().'uploads/'.$news_item['post_image'] ?>" class="img-responsive">

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.