Jump to content

[SOLVED] Pass Variable to directory listing script


DaveRandom

Recommended Posts

Hi

 

I have the following script to produce a directory listing, and I am trying to pass a variable into it so that it will list different directories based on that variable:

 

 


<?php

get_size('uploads');
function get_size($path)
{
$count=0;
  if(!is_dir($path)) return filesize($path);
  if ($handle = opendir($path)) {
    $size = 0;
    while (false !== ($file = readdir($handle))) {
      if($file!='.' && $file!='..' && $file!='.htaccess') {$count++;
        $size = get_size($path.'/'.$file);
$sizekb = $size / 1024;
$sizekb = round($sizekb,2);
$sizemb = ($size / 1024)/1024;
$sizemb = round($sizemb,2);
$sizegb = (($size / 1024)/1024)/1024;
$sizegb = round($sizegb,2);

      ... echo some html code into a table of the results...

      }
    }
    closedir($handle);
    return $size;

  }
}

?>

 

I have been trying to do it with

 


<?php

$myvar = "uploads";
get_size('$myvar');
function get_size($path)

 

at the beginning of the script but this just produces nothing (as if the dir was empty). I have echoed out all the variables to make sure everything is what it says it should be, and cannot figure out why it's not working. Do I have the syntax wrong?

 

If it makes a difference, I will probably be collecting the variables thru http GET.

Archived

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

×
×
  • 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.