Tuesday, 10 March 2015

Display image from a folder in Codeigniter

(1)write  code for  "displayimage.php"  fiel & save into views folder:


$this->load->helper('directory'); //load directory helper

$dir = "uploads/"; // 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;?>"  height="200"  width="200"   alt="">
<?php }

(2)write code for upload_controller.php file  & save inot controllers:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class  Upload_Controller extends CI_Controller


public function __construct()



public function displayimage()






(3)to run  it open browser & type following code:


1 comment: