Daniel Daniel - 2 months ago 7
HTML Question

Can't output images in CodeIgniter using html helper

Im new at CodeIgniter and I want to read some data from mysql database using CodeIgniter. Data I have stored is an image.
I have this folder structure in my aplication:
1.ci


  • application


    • controllers

    • views

    • models

    • upload_images (Here I have the images stored as jpg files)
      When I create this code the image shows up and it is Ok:






echo ' <img src=" http://localhost/ci/'.$row->book_img.' " />'





While when I try to output images from the database in another way like below it outputs the link instead of the image. I want to use html helper and I have loaded it.



echo ' img(' http://localhost/ci/'.$row->book_img.')';





the image doesn't appear. Do I do something wrong in the second way? Thanks!

Answer

The uploads folder should be out side of application folder because the htaccess in the application folder blocks access

application

system

upload_images <-- folder permission 0777

index.php

then make sure you are getting the image correct on controller var_dump($row->book_img)

On controller you might need to do this

$data['img'] = $row->book_img;

$this->load->view('your_view', $data);

View

<img src="<?php echo base_url('upload_images/' . $img);?>;" />

And set your base url

$config['base_url'] = 'http://localhost/yourproject/';