Advice needed; query/filter results

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Sorry for the unclear subject line.

I've got to write a download script for and existing file manager (we
are working on a complete redesign for this file manager, but the
functionality of downloading zipped folders is urgently needed).
Files and folders can be set invisible to the normal user.
They are stored on the HD and are referenced in the database like

id | path | visibility | comment | filetype (file/folder)

Take following example:

/folder/file.ext (visible)
/folder/subfolder (invisible)
/folder/subfolder/otherfile.ext (visible)

When an administrator downloads a folder, ther is no problem as admins
can download everything.
So I tell the zip class to zip the complete folder. No sweat.

But when a user wants to download a folder, the trouble begins as they
should only get files that are visible to them.
First I tried:
SELECT path FROM `documents` WHERE `path` LIKE '$path%' AND
visibility='v' AND `filetype`='file'";
[add files to zipfile using found paths]

But doing a query on the database for visible files doesn't help
because of the way the visiblity is changed in the database.
Changing the visibility of a folder doesn't change the visibility of
the contents of that folder (I know this is not secure, and that's one
of the reasons we are redesigning).
So that way aint the way to go.

I was thinking starting with a query for all files and folders within
the given path (path LIKE $path%) and eliminating within those
So something like this:

function check_if_hidden($path) {
if(one of the parent folders of $path is hidden) {return 1}
else {return 0}

Anyone willing to set me on the right track?
Much appreciated,

Site Timeline