I have a function that is supposed to compare all the folders/subfolders/subsubfolers/etc.. of a specific repertory with the directory the user is currently on. And if there is a match, it is supposed tu return true
.
This function allows me to display different functionnalities for the user depending on weither he has the right permissions on the folder/subfolder he is currently on.
However my function doesn't return true
when the user is in a subfolder1 or deeper (subfolder1, subfolder2, subfolder3...)
Here is what the tree looks like :
main_repertory => folder1 => subfolder1 => subfolder2 => etc...
And here is my function :
function scanDirectory($userdir = '', $directory){
$folders = glob($userdir . '/*' , GLOB_ONLYDIR);
foreach($folders as $folder){
echo($folder.'</br>');
if (($folder == $directory && gator::checkPermissions('r')) || (gator::checkPermissions('ru')) || ($userdir == $directory && gator::checkPermissions('r'))) {
return true;
}
scanDirectory($folder, $directory);
}
return false;
}
scanDirectory($userdir, $directory);
?>
<?php if ($getprivileges == true): ?>
<p>Permissions granted.<p>
<?php endif; ?>
To find where the problem comes from I added echo($folder.'</br>');
and echo($directory);
to see myself if they were displayed, and if they were matching. This is what I got :
( The text in bold being echo($directory);
(current directory of the user), the normal text being the one displayed by the echo($folder);
and "permission granted" being the text displayed when $getprivileges
is true. )
for Folder1 (works also in the main repertory) :
C:/wamp/www/gg/ftp/repository/user/mister/folder1 C:/wamp/www/gg/ftp/repository/user/mister/folder1 C:/wamp/www/gg/ftp/repository/user/mister/folder1 Permissions granted.
for subfolder1 and deeper it stops displaying "permissions granted" even tho the $folder and $directory match :
C:/wamp/www/gg/ftp/repository/user/mister/folder1 C:/wamp/www/gg/ftp/repository/user/mister/folder1/subfolder1 C:/wamp/www/gg/ftp/repository/user/mister/folder1 C:/wamp/www/gg/ftp/repository/user/mister/folder1/subfolder1 C:/wamp/www/gg/ftp/repository/user/mister/folder1/subfolder1
I have been told that it may be caused by me disregarding the return value of the recursive call but I don't really know what that means.
Also I noticed that echo($folder); is displaying me the same paths twice, which is not intended, maybe this is linked to my main issue ?
Any help to fix this function would be really appreaciated !
Thanks a lot.