We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Loop over all json files in directory

I'd like to get all .json files in my directory. Then I did that :

foreach (glob("files/my/path/to/*.json") as $file) {
    echo $file;
}

But this will print the path and the filename and I can't use getName() function. I'd like to use phalcon function like $file->getName() etc... as we can do when we are uploading some files like this :

foreach ($this->request->getUploadedFiles() as $file) {
     echo $file->getName(), " ", $file->getSize(), "\n";
}

There is a way to do this for the files in directory ? Or maybe I can't do that with Phalon and I have to use basename($file) ?



145.0k
Accepted
answer
edited Mar '17

https://php.net/manual/en/class.directoryiterator.php Next time use php docs/google really. Forum is mostly about phalcon questions.

edited Mar '17

Thanks for your answer. That was a question about Phalcon because I asked if there is this a Phalcon Class like Phalcon\Http\Request\File for directory file.

No because php have builtin class.