gpt4 book ai didi

php - 制作像 mega.nz 这样的侧边栏菜单

转载 作者:行者123 更新时间:2023-11-28 02:40:23 25 4
gpt4 key购买 nike

我想在 php 中制作一个侧边栏菜单,就像网站 mega.nz 一样

enter image description here

我试过这段代码:

function foldersList($folderName = NULL) {

$return = '';

$globFolder = ($folderName != NULL ? $folderName : './server/'.$_SESSION['username']) . "/*";


foreach (glob($globFolder, GLOB_ONLYDIR) as $subFolder) {

$baseFolder = basename($subFolder) . '';
// okay let me see
// call function to check subfolders - don't forget write `/`
$subFolders = foldersList($subFolder);

$return .= '<li><a><i class="fa fa-desktop"></i>' . $baseFolder . '<span class="fa fa-chevron-down"></span></a>';
$return .= '<ul class="nav child_menu">';

// if subfolder exist add to return variable
$return .= $subFolders != '' ? $subFolders : '';


$return .= '</ul>';
$return .= '</li>';
}

return $return;
}

但问题是文件夹无法识别文件夹内是否有一个文件夹或文件列表。我想,如果文件夹里面有文件列表,转到另一个链接如果是文件夹,多一个文件夹,做下拉菜单,显示这个文件夹。

最佳答案

要跳过空文件夹或只有文件的文件夹,请将函数更改为:

function foldersList($folderName = NULL) {

$return = '';

$globFolder = ($folderName != NULL ? $folderName : './server/'.$_SESSION['username']) . "/*";

$folders = glob($globFolder, GLOB_ONLYDIR);

if(!empty($folders)) {
foreach ($folders as $subFolder) {

$baseFolder = basename($subFolder) . '';
// okay let me see
// call function to check subfolders - don't forget write `/`
$subFolders = foldersList($subFolder);

$return .= '<li><a><i class="fa fa-desktop"></i>' . $baseFolder . '<span class="fa fa-chevron-down"></span></a>';
$return .= '<ul class="nav child_menu">';

// if subfolder exist add to return variable
$return .= $subFolders != '' ? $subFolders : '';


$return .= '</ul>';
$return .= '</li>';
}
}

return $return;}

关于php - 制作像 mega.nz 这样的侧边栏菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44871091/

25 4 0