note 102959 deleted from function.readdir by danbrown
| From: | danbrown@php.net | Date: | Wed, 16 Mar 2011 23:13:46 +0000 |
| Subject: | note 102959 deleted from function.readdir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177947@lists.php.net to get a copy of this message | ||
Note Submitter: fnord at mk-ult dot ra
----
header ("content-type: text/xml");
Filesystem();
function Filesystem()
{
echo '<filesystem base="'.dirname(__FILE__).'">';
toXMLString('.');
echo '</filesystem>';
}
function toXMLString($path)
{
$dir = getDirectory($path);
foreach ($dir['dir'] as $f)
{
echo '<dir
name="'.str_replace($path,'',$f).'">'."\n";
toXMLString($f.'/');
echo '</dir>'."\n";
}
foreach ($dir['file'] as $f)
{
echo '<file name="'.str_replace($path,'',$f).'"
size="'.round(filesize($f)/1024).'"
create="'.date("d.m.Y H:i:s" ,filectime($f)).'"
change="'.date("d.m.Y H:i:s" ,filemtime($f)).'"
access="'.date("d.m.Y H:i:s"
,fileatime($f)).'"/>'."\n";
}
}
function getDirectory($path)
{
if (!is_dir($path)) return false;
if ($path != '.') $p = $path;
$result = array();
$result['file'] = array();
$result['dir'] = array();
$f = opendir($path);
while (($file = readdir($f)) !== false)
{
if ($file == '.' || $file == '..' || is_link($file))
continue;
if (is_dir($p.$file))
array_push($result['dir'],$p.$file);
else
array_push($result['file'],$p.$file);
}
closedir($f);
sort($result['dir'], SORT_LOCALE_STRING);
sort($result['file'], SORT_LOCALE_STRING);
return $result;
}