<?php
echo "-----------Hello World!----------";
echo "</br>";
foreach(glob('*.*') as $filename)
{
echo '<a href="./'.$filename.'">'.$filename.'</a>';
echo "</br>";
}
echo "-----------Hello World!----------";
echo "</br>";
echo "</br>";
if($handle = opendir('./'))
{
while (false !== ($file = readdir($handle)))
{
echo '<a href="./'.$file.'">'.$file.'</a>';
echo "</br>";
}
closedir($handle);
}
echo "-----------Hello World!----------";
echo "</br>";
echo "</br>";
function tree($directory)
{
$mydir=dir($directory);
while($file=$mydir->read()){
if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!=".."))
{
echo '<a href="./'.$file.'">'.$file.'</a>';
echo "</br>";
tree("$directory/$file");
} else
{
echo '<a href="./'.$file.'">'.$file.'</a>';
echo "</br>";
}
}
echo "\n";
$mydir->close();
}
tree("./");
echo "-----------Hello World!----------";
echo "</br>";
echo "</br>";
echo "-----------Hello World!----------";
echo "</br>";
echo "</br>";
function listDir($dir){
if(is_dir($dir)){
if ($dh = opendir($dir)) {
while (($file= readdir($dh)) !== false){
if((is_dir($dir."/".$file)) && $file!="." && $file!=".."){
echo '<a href="./'.$file.'">'.$file.'</a>';
echo "</br>";
listDir($dir."/".$file."/");
} else{
if($file!="." && $file!=".."){
echo '<a href="./'.$file.'">'.$file.'</a>';
echo "</br>";
}
}
}
closedir($dh);
}
}
}
listDir("./");
echo "-----------Hello World!----------";
echo "</br>";
echo "</br>";
function file_list($dir,$pattern="")
{
$arr=array();
$dir_handle=opendir($dir);
if($dir_handle)
{
while(($file=readdir($dir_handle))!==false)
{
if($file==='.' || $file==='..')
{
continue;
}
$tmp=realpath($dir.'/'.$file);
if(is_dir($tmp))
{
$retArr=file_list($tmp,$pattern);
if(!emptyempty($retArr))
{
$arr[]=$retArr;
}
} else
{
if($pattern==="" || preg_match($pattern,$tmp))
{
$arr[]=$tmp;
}
}
}
closedir($dir_handle);
}
return $arr;
}
print_r(file_list("./"));
echo "-----------Hello World!----------";
echo "</br>";
echo "</br>";
echo "-----------Hello World!----------";
echo "</br>";
echo "</br>";
?>