大虾们指教。a.php遍历并显示文件夹,
比如testfolder里面有a,b,c等多个文件夹,a里面又有a1,a2,a3等多个文件夹,a1里面又有a11,a22,a33等多个文件夹,遍历时显示如:
a
b
c
当点击a文件夹时出一个参数到另一个文件b.php(b.php可以同一服务器或者不同服务器),如何a.php显示a1,a2,a3。
b,c同理。
比如testfolder里面有a,b,c等多个文件夹,a里面又有a1,a2,a3等多个文件夹,a1里面又有a11,a22,a33等多个文件夹,遍历时显示如:
a
b
c
当点击a文件夹时出一个参数到另一个文件b.php(b.php可以同一服务器或者不同服务器),如何a.php显示a1,a2,a3。
b,c同理。
解决方案 »
- 怪事,dede:php 标签不起作用了
- Apache无法安装
- 大侠们,帮帮!关于$arr=$rst->GetAssoc()在PHP中是什么意思?
- 自定义函数内容不能正常显示的问题
- 发送邮件失败,急!
- 大家好,我想修改PHPCMS的标签管理部分,想添加一个区域和行业的属性,但是不得要领,不知道如何改起,请做过PHPCMS二次开发的朋友不吝赐教,在下十分感谢!!可付少量现金报酬或积分!!
- 求一sql语句
- 如何用fopen()从网上读取html文件?(急)
- 对某一表的某一字段或某几字段求和mysql语句怎样写呢?
- 求救,急急急!!此程序在linux下很正常,为何在windows下去不能正常运行
- 一很简单的PHP与MYSQL问题
- 帮帮看看这句sql语句对不?
http://www.php.net/manual/en/function.scandir.php
http://www.php.net/manual/en/function.is-dir.php
返回一个$directory路径下的文件和分支路径的数组。你写个php文件试下就知道了!
function my_scandir($dir)
{
$files=array();
if(is_dir($dir))
{
if($handle=opendir($dir))
{
while(($file=readdir($handle))!==false)
{
if($file!="." && $file!="..")
{
if(is_dir($dir."/".$file))
{
$files[$file]=my_scandir($dir."/".$file);
}
else
{
$files[]=$dir."/".$file;
}
}
}
closedir($handle);
return $files;
}
}
}
print_r(my_scandir("d:\wamp\www\ZF"));
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#trigger").bind("click", function(){
var v = 'a';
$.post("jajax.post.php",{'v':v},function(data){
//window.location.reload();
$('#trigger').html(data) ;
});
});
}) ;</script>
</head>
<body>
<a href="#" id="trigger">click me</a>
</body>
</html>
<?php
if(array_key_exists('v',$_POST)){
echo "V = ".$_POST['v'] ;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>traversal folder</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="js/jquery-1.js" type="text/javascript"></script>
</head>
<style>
.trigger{cursor:pointer;}
li img{vertical-align:middle;}
</style>
<body>
<div id="title"><span></span></div><div id="warning" style="background: none repeat scroll 0% 0% rgb(188, 112, 112); border-bottom: 1px solid rgb(255, 192, 203); border-top: 1px solid rgb(165, 74, 74); color: rgb(0, 0, 0); font-size: 0.8em; padding: 3px; text-align: center; height:35px;">
</div><div id="wrapper">
<ul id="top">
<?
//$dir1 = $_SERVER["DOCUMENT_ROOT"]."/traversalFolder/testUIFolder/a/index.html<br>";$path = 'testUIFolder';
function get_filetree_scandir($path){
$result = array();
$temp = array();
if (!is_dir($path)||!is_readable($path)) return null; //检测目录
$allFiles = scandir($path); //获取目录下所有文件与文件夹
foreach ($allFiles as $fileName) { //遍历一遍目录下的文件与文件夹
if (in_array($fileName,array('.','..'))) continue; //无视 . 与 ..
$fullName = $path.'/'.$fileName; //得到完整文件路径
$fullNameUrlIHTML = $path.'/'.$fileName.'/index.html'; //得到完整文件路径
$fullNameUrlSHTML = $path.'/'.$fileName.'/Setup.html'; //得到完整文件路径
$fullNameUrlIHTM = $path.'/'.$fileName.'/index.htm'; //得到完整文件路径
$fullNameUrlSHTM = $path.'/'.$fileName.'/Setup.htm'; //得到完整文件路径
$link = $_SERVER["REQUEST_URI"];
$linkAnalysis = parse_url($link);
$linkDecomposition = explode('/',$linkAnalysis['path']);
//echo $linkc[1];
//echo $fullName."<br>";
if(!in_array($fullName,array('index.html','index.htm','Setup.html','Setup.htm'))){
//$url = "http://".$_SERVER['HTTP_HOST']."/".$linkDecomposition[1]."/traversalFolder/".$path."/".$fileName;
$url = "http://".$_SERVER['HTTP_HOST']."/".$linkDecomposition[1]."/".$path."/".$fileName;
}else{
$url = "javascript:void(0)";
}
//echo $fullName."<br>";
if (is_dir($fullName)) { //如果是目录的话继续递归
if (!file_exists($fullNameUrlIHTML) && !file_exists($fullNameUrlIHTM) && !file_exists($fullNameUrlSHTML) && !file_exists($fullNameUrlSHTM)) {
echo "<li>\n";
echo "<a class=\"trigger\"><img src=\"image/directory.png\" border=\"0\"> $fileName</a>\n";
}else{
echo "<ul style=\"display: block;\" class=\"sub\"> ";
echo "<li><a href=\"$url\" class=\"trigger\"><img src=\"image/directory.png\" border=\"0\"> $fileName</a></li>\n";
echo "</ul>\n";
echo "</li>\n";
}
/*
echo "<ul style=\"display: block;\" class=\"sub\"> ";
echo "<img src=\"image/directory.png\" border=\"0\"> $fileName";
echo "</ul>\n";
*/
$result[$fileName] = get_filetree_scandir($fullName); //递归开始
}else {
//$url = "http://".$_SERVER['HTTP_HOST']."/traversalFolder/".$path."/".$fileName;
//echo "<li><a href=\"$url\">".$fileName."</a></li>\n";
$temp[] = $fileName; //如果是文件,就存入数组
}
} foreach ($temp as $tmp) { //把临时数组的内容存入保存结果的数组
$result[] = $tmp; //这样可以让文件夹排前面,文件在后面
}
return $result;
}print_r(json_encode(get_filetree_scandir($path)));?> </ul>
</div>
<script type="text/javascript">
$(function() {
$('.sub').hide();
$('.trigger').click( function() {
$(this).next('.sub').slideToggle();
});
});
</script></body>
</html>