Tuesday, 10 March 2015

Display image from a folder in Codeigniter

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

<?php

$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()

{
parent::__construct();

$this->load->helper('url');
}

public function displayimage()

{

$this->load->view('displayimage');



}


}


?>


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

  "localhost/ci/index.php/upload_controller/displayimage"

1 comment: