[UPHPU] simple??? php function (display an index)

Caleb Call caleb at macjunk.org
Wed Jul 19 21:59:36 MDT 2006


thanks, that got me going, I found some examples.  (This php stuff is  
all new but great to finally get playing with it).  This is what I  
have so far, can anyone suggest a better way to do any of it?

<?
$DocName = "" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
$DirNow = dirname($DocName);

$drop = array("www.", "yourwebsite", ".com/");
# here you drop the url, ex: www.yourwebsite.com/
$pickup = array("", "", "");

$folder = str_replace($drop, $pickup, $DirNow);
echo "<b>Index of $folder</b><br>";

?>
<br>
<br>
<?php

if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && $file != "index.php" &&  
$file != "index.html") {
        	   $file_size = filesize($file);
        	   $file_size = round(($file_size/1024),0);
            echo "<a href=$file <br>$file\t\t\t</a>$file_size KB<br>\n";
        }
    }
    closedir($handle);
}
?>

is there a way I can display KB on smaller files and MB on larger  
files?  I would assume a loop, something like this?

if ($file_size >= 1024) {
			echo "($file_size/1024) MB";
            } else {
            	echo "($file_size) KB";
            }

it's not working so I know there is something wrong with it, but what???



On Jul 19, 2006, at 4:53 PM, Brady Mitchell wrote:

>
>> -----Original Message-----
>> One last question, to add on to this a little, where you have
>> "Select the file you want to go to:" is there a way to display the
> current
>> directory you are in so it could read "Index of <Current directory>"
>> or say what ever but display the current directory?
>
> Take a look at the dirname() function.
> http://us2.php.net/manual/en/function.dirname.php
>
> Brady



More information about the UPHPU mailing list