Getting the Type of a File

Problem

You want to know what the type of a file is.

Solution

Use the File::type() method.

echo File::type($filename);

Usually this returns "file" or "dir".

Discussion

Watch out for errors.

If you try to get the type of non-existent files or files you don't have access to, errors will occur.

comments powered by Disqus