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

            $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>
          <?php echo "<hr>"; ?></p>
          <?php endforeach; ?>
          <?php }else{ ?>
          That's strange, no news items were found.
          <?php } ?>

How do i display the image?

Solution was

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

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

I write the code to show dynamically image but i have different size of image how can i show the images fixed size in frontend

t_1, can you please start a new discussion thread which explains your specific problem? Unless, are you using the code provided by Ventech_IT??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.