Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started