-1

Receiving this error when using PHP to create an image gallery; "Strict Standards: Only variables should be passed by reference in (filename) on line 5"

Does anyone know how to either fix or hide this error? As the actual gallery works fine with the error. Thanks!

Below is the code:

public function getImages($extensions = array('jpg', 'png')) {
    $images = $this->getDirectory($this->path);

        foreach($images as $index => $image) {
            $extension = strtolower(end(explode('.', $image)));
            if(!in_array($extension, $extensions)) {
                unset($images[$index]);
            } else {
                $images[$index] = array(
                    'full' => $this->path . '/' . $image,
                    'thumb' => $this->path . '/thumbs/' . $image,
                    );
            }
        }

    return (count($images)) ? $images : false;
}
Meowls
  • 59
  • 1
  • 5

1 Answers1

1

end() requires an actual array because it will move the pointer to the end.

end(explode('.', $image)) will not work.

Instead you could try for instance: $extension = pathinfo($image, PATHINFO_EXTENSION);

Maarten van Middelaar
  • 1,691
  • 10
  • 15