I used codeigniter default helper function to map the directory
$path = 'user_uploads';
$data = directory_map($path);
and i do a
var_dump($data);
and the result is
array(9) { [0]=> string(12) "SDC10027.JPG" [1]=> string(12) "SDC10028.JPG" [2]=> string(12) "SDC10029.JPG" [3]=> string(12) "SDC10030.JPG" [4]=> string(12) "SDC10031.JPG" [5]=> string(12) "SDC10032.JPG" [6]=> string(12) "SDC10033.JPG" [7]=> string(12) "SDC10034.JPG" [8]=> string(12) "SDC10035.JPG" }
what i need is i want to show each and every image in a web page like this.
<img src="<?php echo base_url() . 'user_uploads/'. $image; ?>"/>
$image is the image names that are read through the directory_map() function.
the only thing i need to know is how to take those directory_map() return array image names to $image variable.
You could loop through the array, it would look something like this:
<?php foreach($data as $image): ?>
<img src="<?php echo base_url() . 'user_uploads/'. $image; ?>"/>
<?php endforeach; ?>
Or an alternative way to write it...
foreach($data as $image)
{
echo '<img src="' . base_url() . 'user_uploads/' . $image '"/>';
}
Or if you want to access each image individually you can do so like this:
$data[0]; //returns 'SDC10027.JPG'
$data[1]; //returns 'SDC10028.JPG'