<?php
class listfile{
var $callFunc; //操作函数,用于lisDirTree里的调用
var $extname; //有效文本文件的扩展名。
function listfile()
{
echo 'initialize filetree<BR>';
} // end func
/** 函数 listDirTree( $dirName = null )
* 功能 对目录下所有文件及子目录下所有文件进行操作
* 参数 $dirName 目录名称
*/
function listDirTree( $dirName = null )
{//global $tree;
if( empty( $dirName ) )
exit( "IBFileSystem: directory is empty." );
if( is_dir( $dirName ) )
{
if( $dh = opendir( $dirName ) )
{
//$tree = array();
while( ( $file = readdir( $dh ) ) !== false )
{
if( $file != "." && $file != ".." )
{
$filePath = $dirName . "/" . $file;
if( is_dir( $filePath ) )//为目录,递归
{
//$tree[$file] = $this->listDirTree( $filePath );
$this->listDirTree( $filePath );
}
else//为文件,进行处理
{ //echo "文件处理函数为 $this->callFunc <BR>";
eval($this->callFunc);
//$tree[] = $file;
} //文件处理结束
}
}
closedir( $dh );
}
else
{
exit( "IBFileSystem: can not open directory $dirName.");
}
//返回当前的$tree
//return $tree;
}
else
{
exit( "IBFileSystem: $dirName is not a directory.");
}
}//</listDirTree>
/**
* mkdirp is used to instead of mkdir ,mkdirp can create deep multiple directory.
*/
function mkdirp($target) {
// If the path already exists && is a directory, all is well.
// If the path is not a directory, we've a problem.
if (file_exists($target)) {
if (!is_dir($target)) return false;
else return true;
}
// Attempting to create the directory may clutter up our display.
if ( @mkdir($target) ) return true;
// If the above failed, attempt to create the parent node, then try again.
if ( $this->mkdirp(dirname($target)) ) return $this->mkdirp($target);
return false;
}//</function mkdirp>
}//</class listfile>
?>
echo.php
<?php
function echot(&$str){
echo '<TEXTAREA NAME="" ROWS="5" COLS="80">'.$str.'</TEXTAREA>';
}
/**
* echothead
*/
function echothead()
{
echo '<TEXTAREA NAME="" ROWS="20" COLS="80">';
} // end func echothead
/**
* echotfoot
*/
function echotfoot()
{
echo "</textarea>";
} // end func
function pr(&$row){
echo "<pre>";
print_R($row);
}
function echosql($q){
$q = str_replace("#_","mos",$q);
echo "$q <br/>\n";
}
function echoredsql($q){
$q = str_replace("#_","mos",$q);
echo "<font color=red> $q </font>\n";
}
function echored($str){
echo "<font color=red> $str </font>\n";
}
/**
* show table,$rows is get by $database->loadOjbectLIst();
*/
function rowstable(&$rows)
{$n=count($rows);
if ($n>0) {
//pr($rows);
$obj = $rows[0];
$fields=get_object_vars($obj) ;// pr($fields);
$cnt = "<table class=\"dxtable\">\n";
for ($i=0;$i<$n ;$i++ ) {
$cnt .="<tr>\n";
foreach($fields as $key=>$value){
//echo "$key=$value";
$cnt .= "<td>".$rows[$i]->$key."</td>\n";
}
$cnt .="</tr>\n";
}
$cnt.="</table>\n";
echo $cnt;
}
} // end func
/**
* prt
*/
function prt($arr)
{
echothead();
print_R($arr);
echotfoot();
} // end func
?>