...

View Full Version : DIR list Help



mnieves
08-11-2008, 03:35 PM
i need to add filesize and hide extension filter to this code.
thanks in advance.

<?php
$str = "<root>";

function readfromhere($path=".")
{
global $str;
$currentPath=($path == '.' ? './Shared/' : $path.'/');
//echo "";
//var_dump($currentPath);
//echo "";
if ($handle = opendir($currentPath)) {
while (false !== ($file = readdir($handle))) {
//echo "";
//var_dump($file);
//echo "\n";
//var_dump(is_dir($currentPath.$file));
//echo "";

if (is_dir($currentPath.$file) && $file != "." && $file != "..") {
$str.='<node type="folder" name="'.$file.'">';
readfromhere($currentPath.$file);
$str.='</node>';
} else if ($file != "." && $file != "..") {
$str.='<node type="file" name="'.$file.'" path="'.preg_replace('/\.\/+/i','',$currentPath).$file.'">
</node>';
}
}
closedir($handle);
}
return $str;
}

readfromhere();
$str.="</root>";

header('Content-Type: text/xml');
echo $str;
?>

zackwiny
08-11-2008, 11:35 PM
i need to add filesize and hide extension filter to this code.
thanks in advance.


<?php
$str = "<root>";

function readfromhere($path=".")
{
global $str;
$currentPath=($path == '.' ? './Shared/' : $path.'/');
//echo "";
//var_dump($currentPath);
//echo "";
if ($handle = opendir($currentPath)) {
while (false !== ($file = readdir($handle))) {
//echo "";
//var_dump($file);
//echo "\n";
//var_dump(is_dir($currentPath.$file));
//echo "";

if (is_dir($currentPath.$file) && $file != "." && $file != "..") {
$str.='<node type="folder" name="'.$file.'">';
readfromhere($currentPath.$file);
$str.='</node>';
} else if ($file != "." && $file != "..") {
$str.='<node type="file" name="'.$file.'" path="'.preg_replace('/\.\/+/i','',$currentPath).$file.'">
</node>';
}
}
closedir($handle);
}
return $str;
}

readfromhere();
$str.="</root>";

header('Content-Type: text/xml');
echo $str;
?>

File Size:
$filesize = filesize($file);

Extension filter:
$path_info = pathinfo($file);
$filtered = $path_info['filename'];

There you go :)
(This is assuming $file is ur file handle)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum