N
N
Nikolai Gromov2018-05-11 11:35:18
Zend Framework
Nikolai Gromov, 2018-05-11 11:35:18

How to select files by extension?

Hello.
I have a method that makes a selection by two criteria, by parentId and image. These are table fields.

public function getFotoByParentIdWithPng ()
    {
        $asutpService = $this->getAsutpRepository();
        $foto = ['parentId' => '2',
            'image' => 'sh1.png'];
        return $asutpService->findBy($foto);
    }

tell me what I need to write in this line 'image' => 'sh1.png' instead of sh1, so that the method would search for all files with the extension .png? If you write specifically the file name as in the code above, then it normally finds it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-05-11
@Tuborg

There is such a class as SplFileInfo
php.net/manual/en/splfileinfo.getextension.php

$file = new SplFileInfo($filepath);
var_dump($file->getExtension());

And then you check

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question