Forum Moderators: coopster
[pre][quote]<?
$html = "<table width=80% cols=2>";
function display($dir) {
$d = dir($dir);
while ($f = $d->read()) {
if(($f!= ".") && ($f!= "..")) {
if(is_dir($f)) {
$ds = $dir.$f."/";
display($ds);
}else{
$html .= "<tr><td>".$dir.$f."</td><td>".filesize($dir.$f)."</td></tr>";
}
}
}
}
display("./");
echo $html;
?>[/quote][/pre]
<?
function display($dir) {
global $html;
$html = "<table width=80% cols=2>";
$d = dir($dir);
while ($f = $d->read()) {
if(($f!= ".") && ($f!= "..")) {
if(is_dir($f)) {
$ds = $dir.$f."/";
display($ds);
}else{
$html .= "<tr><td>".$dir.$f."</td><td>".filesize($dir.$f)."</td></tr>";
}
}
}
}
display("./");
echo $html;
?>
note the global var, I changed it to echo inside the function which told me it was just a scope issue.
<table width=80% cols=2><tr><td>./aaaaa/index.php</td> <td>294</td></tr><tr><td>./math.php</td> <td>58</td></tr><tr><td>./cookiepass.php</td> <td>449</td></tr><tr><td>./func.php</td><td>113</td> </tr><tr><td>./size.php</td><td>337</td></tr>
as you might guess i have way more than 5 files on my server
any thoughts on why it stopped?
does it work for you?
[edited by: jatar_k at 9:43 pm (utc) on June 1, 2004]
[edit reason] fixed sidescroll [/edit]
<?
function display($dir) {
$d = dir($dir);
while ($f = $d->read()) {
if(($f!= ".") && ($f!= "..")) {
if(is_dir($f)) {
$ds = $dir.$f."/";
$innerstuff = display($ds);
$html .= $innerstuff;
}else{
$html .= "<tr><td>".$dir.$f."</td><td>".filesize($dir.$f)."</td></tr>\n";
}
}
}
return $html;
}
echo "<table width=80% cols=2>\n";
$stuff = display("./");
echo $stuff;
echo "</table>\n";
?>
instead of
$html .= "<tr><td>".$dir.$f."</td><td>".filesize($dir.$f)."</td></tr>\n";
then
$myarr[] = array($dir.$f,filesize($dir.$f));
then you would need to sort them when completed and then have a loop to convert to html and return
I think for the multidimensional array you could use array_multisort [ca.php.net] but if you make the filename the key them you can use natsort. My code would be wrong then though.