find if a folder belongs to other

I want to make a function that check the permisions at a folder (or a file ) of a user.

That means that this folder (or the file) must be a subfolder (or belongs to subfolder) of the default (from db) folder that belongs to user.

Is there a simpler method than making a loop at subfolders of ‘default’ folder?

If the default folder full path is a substring of subfolder/file full path you want to check permission against, then the user is granted.