Question: Codeigniter: Hiding non-image file types for a gallery. Hello, I'm trying to make a gallery using codeigniter and it works, but for some reason, other

Codeigniter: Hiding non-image file types for a gallery.

Hello,

I'm trying to make a gallery using codeigniter and it works, but for some reason, other files are showing up as blank images in the thumbnail gallery. I tried using glob, but I don't know how it works exactly or where to best put it. I tried using something like

$files = glob("*.{jpg,png,gif}", GLOB_BRACE); 

But I assume I'm putting it in the wrong spot. Or it's part of my file structure that is causing the issue.

In my Model for the gallery, I have:

function Gallery_model() {

$this->gallery_path = realpath(APPPATH . '../images');

$this->gallery_path_url = base_url().'images/';

}

function get_images() {

$files = scandir($this->gallery_path);

$files = array_diff($files, array('.', '..', 'thumbs'));

$images = array();

foreach($files as $file) {

$images []= array (

'url' => $this->gallery_path_url . $file,

'thumb' => $this->gallery_path_url . 'thumbs/' . $file

);

}

return $images;

}

Is there a good way to use glob to only show .jpg, .jpeg, .gif, or .png files? And if so, where should I put it in the code? Thanks!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!