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.
<?php 
$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.

Comments

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

    ReplyDelete
  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?

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

    udin

    ReplyDelete

Post a Comment

Popular Posts