Desplegables de carpetas PHP

I am trying to make a dropdown menu of folders stored on a site. For example the top level would be a list of folders, and when the user hovers over the folder name, a dropdown appears so the user can see all of the files within. I'm very new to PHP and have tried a few things, but can't get the dropdowns to work. Any suggestions?

EDIT: Additional information from comments:

Por el momento estoy usando este, which displays the top layer, but it gets the contents of the folders to list in a dropdown, which is the problem. For the first layer I have

$thelist .= '<li><a target="frame" href="unzip/uncompressed/'.$file.'">'.$file.'</a></li>';

and can display all the contents of all the folders with

$thelist2 .= '<li><a target="frame" href="unzip/uncompressed/'.$file.'/'.$file2.'">'.$file2.'</a></li>';

I just can't get it to display in dropdowns.

preguntado el 08 de noviembre de 11 a las 16:11

This is not PHP, it is CSS and/or Javascript. Search Google for a CSS or Javascript drop-down menu -

"im very new to php and have tried a few things but cant get the drop downs to work", Can you show us what you have tried?? -

at the moment im using enlace which displays the top layer but its getting the contents of the folders to list in a drop down which is the problem. so i have $thelist .= '<li><a target="frame" href="unzip/uncompressed/'.$file.'">'.$file.'</a></li>';. for the first layer and can display all the contents of all the folders with $thelist2 .= '<li><a target="frame" href="unzip/uncompressed/'.$file.'/'.$file2.'">'.$file2.'</a></li>'; just cant get it to display in drop downs -

2 Respuestas

PHP could be used to get and output the list of files and folders see : PHP's Directory Documenation. You would use css/javascript for the styling and user's interaction with the tree.

Un rápido google will give you lots of tutorials.

respondido 08 nov., 11:20

Encontré la respuesta myself. Quote:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Untitled Document</title>
        <link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css">
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
        <script type="text/javascript" src="http://twitter.github.com/bootstrap/1.4.0/bootstrap-dropdown.js"></script>
    </head>
    <body>
<?php 

if ( $handle = opendir($_SERVER['DOCUMENT_ROOT'] . "/menu/") ) {
    while(false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $var .= $file . ",";
        }
    }
}

$var = explode(',', $var);

echo " <ul class='tabs'>";
foreach($var as $v){
    if(!preg_match("/php/i", $v)) {
        echo "<li class='dropdown' data-dropdown='dropdown'><a href='" . $v . "' class='dropdown-toggle'>" . $v . "</a><ul class='dropdown-menu'>";
        $folder = $v;
        $t = opendir($_SERVER['DOCUMENT_ROOT'] . "/menu/" . $v);
        while(false !== ($v = readdir($t))) {
            if ($v != "." && $v != "..") {
                echo "<li><a href='" . $folder ."/". $v . "'>" . $v . "</a></li>";
            }
        }
        echo "</ul></li>";
    }
} 
echo " </ul>";

?>
    </body>
</html>

respondido 10 nov., 11:19

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.