DaveRandom Posted February 26, 2009 Share Posted February 26, 2009 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. Link to comment https://forums.phpfreaks.com/topic/146997-solved-pass-variable-to-directory-listing-script/ Share on other sites More sharing options...
trq Posted February 26, 2009 Share Posted February 26, 2009 Variables are not interpolated within single quotes, try.... $myvar = "uploads"; get_size($myvar); Link to comment https://forums.phpfreaks.com/topic/146997-solved-pass-variable-to-directory-listing-script/#findComment-771722 Share on other sites More sharing options...
DaveRandom Posted February 26, 2009 Author Share Posted February 26, 2009 Sorted, thanks very much! Link to comment https://forums.phpfreaks.com/topic/146997-solved-pass-variable-to-directory-listing-script/#findComment-771729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.