Jump to content


Photo

includes and relative paths question


  • Please log in to reply
No replies to this topic

#1 mfaerber

mfaerber
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 08 May 2006 - 03:47 AM

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:

<?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>"; 
?>

Thank you in advance!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users