Very odd problem with PHP not seeing files

I’ve got this weird problem where PHP can see most of the files in a directory, but not all of them. They all have the same owner, group, and permissions. I’m using PHP’s scandir to get a list of files in a directory, and have also tried readdir and glob with the same results.

Doing a specific test with file_exists on one of the files that PHP lists using scandir and one it misses, I’ve found that when I use a relative path it can’t see the missing file. However if I use an absolute path then it can see both of the files.

But using scandir or glob, even with an absolute path it still can’t see all the files (no difference from using a relative path).

The setup is this - I have a directory with the PHP files in. Within this directory is an ‘Img’ directory, which is a symlink to a directory on block storage. The PHP script then uses scandir to get a list of files within a sub-dir of the ‘Img’ dir.

Anyone got any ideas?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @djeyewater,

Can you provide us with the path of scandir? Scandir does not work recursively. It only scans the path input into it. If you have more than one subdirectory in your Img folder, it would explain why one file is shown and another is not.

As for the relative and absolute paths, if you are executing scandir from a different directory than the originally intended one, it would explain why it doesn’t work.

Regards, KDSys