Fclose() error when downloading multiple files

I’m getting an error when trying to download a folder ; the zip file is empty and the log says:

fclose(): Argument #1 ($stream) must be of type resource, bool given


It correspond to this code:

                                try {
                                        $fh = $file->fopen('r');
                                } catch (NotPermittedException $e) {
                                        $internalDir . $file->getName(),

I assume fopen throws an exception which is not handled, but I don’t know which one.

How can I ouput the exception?

After some digging, I found that one of the hundred uploaded files has different permissions:
instead of

All the files where uploaded together, so I don’t know why…