use a variable to pass to opendir(), like $dir. Then while iterating thru you file array do an "is_dir" check on each entry, if it returns true then have that entry be link to the same script ($PHP_SELF) and pass the varibale of that dir ($PHP_SELF?dir=$dir)