Jump to content

Archived

This topic is now archived and is closed to further replies.

mfaerber

includes and relative paths question

Recommended Posts

Behold, as I contruct an unnecessarily long explanation for my simple problem:

The Situation:

I have page A and page B, and page B is 2 folders deep within page A. Page A is an index.php file with an include statement that calls upon page B. Page B has code in it that prints out the stats (filze sizes) of the folder within it.

The Problem:

When I go to page A in my browser, I see the stats for the folders relative to page A, not page B. I have not been able to figure out how to add absolute paths to the script within page B, as I know this would solve this. Is that what I want to do, and where do I put them, OR is there a simpler way?

Here is the relevant code for page B:

[code]<?php
function foldersize( $path )
{
  $size = 0;
  if( $dir = @opendir( $path )) {
    while(($file = readdir($dir)) !== false ) {
      if( is_dir( "$path/$file" ) && $file != '.' && $file != '..' ) {      
       $size += foldersize( "$path/$file" );
      }
      if( is_file( "$path/$file" )) {
        $size += filesize( "$path/$file" );
      }
    }
    closedir($dir);
  }
  return $size;
}

$sizes['files'] = 0;
if( $dir = @opendir( '.' )) {
  while(($file = readdir($dir)) !== false ) {
    if( is_dir( "$file" ) && $file != '.' && $file != '..' ) {
     $sizes[$file] = foldersize( "$file" );
    }
    if( is_file( "$file" )) {
      $sizes['files'] += filesize( "$file" );
    }
  }
  closedir($dir);
}

$totsize = 0;
foreach( $sizes as $fsize ) {
  $totsize += $fsize;
}

echo "<table>";
foreach( $sizes as $key => $size ) {
  $perc = 100 * $size / $totsize;
  $width = 4 * $perc;
  $percstr = number_format( $perc, 1 ) . '%';
  $sizestr = number_format( $size );
  $dir = "/images/100/";
  printf( '<tr><td>%s</td><td align="right">%s</td><td><img src="red_dot.gif" width="%s" ' .
    'height="10" border="0" alt="%s"> %s</td>', $key, $sizestr, $width, $percstr,$percstr );  
}
echo "</table>";
?>[/code]

Thank you in advance!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.