Jump to content

includes and relative paths question


mfaerber

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.