×î½üÓÃphp½øÐÐÎļþĿ¼ÐÅÏ¢¶ÁÈ¡£¬ÔÚÍøÉÏŪµ½ÏÂÃæÒ»¶Î´úÂ룺
//»ñÈ¡Ö¸¶¨Ä¿Â¼ÏµÄÎļþÁбí
//$path Ö¸¶¨µÄĿ¼£¬Ä¬ÈÏΪµ±Ç°Ä¿Â¼
//$ifchild ÊÇ·ñÏÔʾ×ÓĿ¼ÎļþÁÐ±í£¬Ä¬Èϲ»ÏÔʾ
//$curpath ÏÔʾµ±Ç°µÄ·¾¶£¬Ä¬ÈÏΪ´Óµ±Ç°Ä¿Â¼¿ªÊ¼£»Õâ¸öÖ÷ÒªÊÇΪÁËÏÔʾȷ¶¨href·¾¶
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
function openpath($path=".",$ifchild=false,$curpath=".")
{
$handle = opendir($path);
if($handle)
{
while(false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$fullPath = $path.DIRECTORY_SEPARATOR.$file;
if(is_dir($fullPath))//Èç¹ûÊÇĿ¼Îļþ
{
if($ifchild)//Èç¹ûÉèÖÃÁËÏÔʾ×ÓĿ¼
{
//µÝ¹é
openpath($path.DIRECTORY_SEPARATOR.$file,$ifchild,$curpath.DIRECTORY_SEPARATOR.$file);
}
else
{
echo "<li><a href=\"$curpath/$file \" target=\"_blank\">$file</a></li>\n";
}
}
else if($file != basename(__FILE__))//Åųýµ±Ç°Ö´Ðнű¾
{
echo "<li><a href=\"$curpath/$file \" target=\"_blank\">$file</a></li>\n";
}
else
{
echo $file;
}
}
}
}
closedir($handle);
}
ÒòΪ×Ô¼ºÒªÌṩ·¾¶Ñ¡ÔñµÄ¹¦ÄÜ£¬×îºÃÊÇÓÐÒ»¸öÏÂÀ²Ëµ¥£¬ÀïÃæÓдýѡ·¾¶µÄÏÔʾ£¬ÕâÑù·½±ãºÜ¶à£¬ÓÚÊÇ×Ô¼º¸ÄÁ˸ģ¬°Ñ·¾¶Êä³ö³ÉÒ»¸öÎÞÐòÁÐ±í¡£
ÏÂÃæÊÇÒ»¸öÈ¡µÃµ±Ç°ÎļþÏÂËùÓÐ×ÓÎļþ·¾¶µÄ´úÂ룺
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
/*»ñÈ¡Ö¸¶¨Ä¿Â¼Îļþ·¾¶Áбí
*$path Ö¸¶¨µÄĿ¼£¬Ä¬ÈÏΪµ±Ç°Ä¿Â¼
*$ifchild ÊÇ·ñ»ñÈ¡×ÓĿ¼ÎļþÁÐ±í£¬Ä¬Èϲ»»ñÈ¡
*$curpath ÏÔʾµ±Ç°µÄ·¾¶£¬Ä¬ÈÏΪ´Óµ±Ç°Ä¿Â¼¿ªÊ¼
*&$pach_html_srt ´«µÝÒ»¸öÍⲿ±äÁ¿µÄÒýÓýøÀ´£¬ÒòΪ´Ë·½·¨ÓпÉÄܱ»µÝ¹éµ÷Óã¬ËùÒÔÒÔÕâÑùµÄ·½Ê½À´±£´æ
*
һЩÐÅÏ¢£¬Ò²¿ÉÒÔÓÃÈ«¾Ö±äÁ¿À´ÊµÏÖ£¬ÔÚº¯ÊýÄÚ²¿±äÁ¿¸Ä±äÒ²Ó°Ïìµ½Íⲿ¡£
*&$path_ref_count ÔÀíͬÉÏ£¬Ò»¸ö¼ÆÊý±êÖ¾£¬Èç¹ûµÝ¹é£¬¼ÆÊýÆ÷´ÓÉÏÒ»´Î±£´æµÄÖµ¿ªÊ¼×ÔÔö
*/
function openpath($path=".",$ifchild=false,&$path_html_str,&$path_ref_count)
{
$handle = opendir($path);
if($handle)
{
while(false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$fullPath = $path.DIRECTORY_SEPARATOR.$file;
if(is_dir($fullPath))//Èç¹ûÎļþÊÇĿ¼
{
$path_html_str.='<li>';
$path_html_str.=$file.'<ul>';
if($ifchild)
{
//µÝ¹é
openpath($path.DIRECTORY_SEPARATOR.$file,$ifchild,&$path_html_str,&$path_ref_count);
}
$path_html_str.='</ul></li>';
}
}
}
}
closedir($handle);
}
ÓÐÁËÉÏÃæµÄ·½·¨£¬ÎҾͿÉÒÔÔÚǰ̨ÓÃjquery mcDropdown²å¼þÀ´ÈÃÓû§¿ÉÒÔͨ¹ýÏÂÀ²Ëµ¥Ñ¡ÔñÏë½øÈëµÄĿ¼£¬ËùÒÔÐèÒª·â×°³ÉÖ¸¶¨¸ñʽ£º
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
$path_ref_count = 1;
$path_html_str ='';
openpath(".",true,&$path_html_str,&$path_ref_count);
$path_html_str = '<ul>'.$path_html_str.'</ul>';
$path_html_str = str_replace ( "<ul></ul>", '', $path_html_str );
ÕâÑùÎÒ°Ñ$path_html_str´«µ½Ç°Ì¨£¬ÏÔʾ³öÀ´µÄ¾ÍÊÇÒ»¸ö·ûºÏmcDropdownÒªÇóµÄÎÞÐòÁÐ±í£¬¾Í¿ÉÒÔÏÔʾÏàÓ¦µÄ´ýÑ¡ÁбíÁË¡£
ÍêÕû´úÂëÈçÏ£º
test.html
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>test</title>
<script type="text/javascript" src="./lib/jquery.js?1.1.5"></script>
<script type="text/javascript" src="./lib/jquery.mcdropdown.js?1.1.5"></script>
<script type="text/javascript" src="./lib/jquery.bgiframe.js?1.1.5"></script>
<!---// load the mcDropdown CSS stylesheet //--->
<link type="text/css" href="./css/jquery.mcdropdown.css?1.1.5" media="all" />
<script type="text/javascript">
$(document).ready(function (){
var delim = "#delim#";
dd= $("#category").mcDropdown("#categorymenu",{
allowParentSelect:true,
delim:delim
});
});
</script>
</head>
<body>
<p>
Please select a category:<br />
<input type="text" value="" />
</p>
#categorymenu#
</body>
</html>
test.php
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
<?php
//Ŀ¼ÐÅÏ¢´¦Àí
$path_ref_count = 1;
$path_html_str ='';
openpath(".",true,&$path_html_str,&$path_ref_count);
$path_html_str = '<ul>'.$path_html_str.'</ul>';
$path_html_str = str_replace ( "<ul></ul>", '', $path_html_str );
//var_dump($path_info);
//var_dump($path_html_str);
$str_buffer = file_get_contents (dirname(__FILE__).DIRECTORY_SEPARATOR.'test.html');
$str_buffer = str_replace ( "#categorymenu#", $path_html_str, $str_buffer );
$str_buffer = str_replace ( "#delim#", DIRECTORY_SEPARATOR, $str_buffer );
echo $str_buffer;
/*»ñÈ¡Ö¸¶¨Ä¿Â¼Îļþ·¾¶Áбí
*$path Ö¸¶¨µÄĿ¼£¬Ä¬ÈÏΪµ±Ç°Ä¿Â¼
*$ifchild ÊÇ·ñ»ñÈ¡×ÓĿ¼ÎļþÁÐ±í£¬Ä¬Èϲ»»ñÈ¡
*$curpath ÏÔʾµ±Ç°µÄ·¾¶£¬Ä¬ÈÏΪ´Óµ±Ç°Ä¿Â¼¿ªÊ¼
*&$pach_html_srt ´«µÝÒ»¸öÍⲿ±äÁ¿µÄÒýÓýøÀ´£¬ÒòΪ´Ë·½·¨ÓпÉÄܱ»µÝ¹éµ÷Óã¬ËùÒÔÒÔÕâÑùµÄ·½Ê½À´±£´æ
*
һЩÐÅÏ¢£¬Ò²¿ÉÒÔÓÃÈ«¾Ö±äÁ¿À´ÊµÏÖ£¬ÔÚº¯ÊýÄÚ²¿±äÁ¿¸Ä±äÒ²Ó°Ïìµ½Íⲿ¡£
*&$path_ref_count ÔÀíͬÉÏ£¬Ò»¸ö¼ÆÊý±êÖ¾£¬Èç¹ûµÝ¹é£¬¼ÆÊýÆ÷´ÓÉÏÒ»´Î±£´æµÄÖµ¿ªÊ¼×ÔÔö
*/
function openpath($path=".",$ifchild=false,&$path_html_str,&$path_ref_count)
{
$handle = opendir($path);
if($handle)
{
while(false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$fullPath = $path.DIRECTORY_SEPARATOR.$file;
if(is_dir($fullPath))//Èç¹ûÎļþÊÇĿ¼
{
$path_html_str.='<li>';
$path_html_str.=$file.'<ul>';
if($ifchild)
{
//µÝ¹é
openpath($path.DIRECTORY_SEPARATOR.$file,$ifchild,&$path_html_str,&$path_ref_count);
}
$path_html_str.='</ul></li>';
}
}
}
}
closedir($handle);
}
?>
jquery mcDropdown ²å¼þ¿ÉÒÔÔÚÕâÀïÏÂÔØ£º
¡¡