Monday, June 16, 2014

How To Display Images From Folder Using Codeigniter?

If you need to display images from folder/directory in the CodeIgniter, then the Directory Helper is what you looking for. The Directory Helper file contains functions that assist in working with directories.
$this->load->helper('directory'); //load directory helper
$dir = "uploads/images/"; // Your Path to folder
$map = directory_map($dir); /* This function reads the directory path specified in the first parameter and builds an array representation of it and all its contained files. */

foreach ($map as $k)
     <img src="<?php echo base_url($dir)."/".$k;?>" alt="">
<?php }

Result: You will get all the images from the folder.


  1. hi thanks for code
    i want to ask how to display label on image in codeignater

  2. Thanks for the code,
    just a quick question, where do you put the code using te MVC model. does it go in te views directory?

  3. what if the folder has subfolder and subfolder how to show it?
    many thanks


  4. It works .But have a doubt that hoe can i apply css to the images that we loaded using the above code????

  5. how can we get order by data in folder