Re: Help with directory listing code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, February 21, 2007 10:41 am, Joker7 wrote:
> Hi -
> I'm having a bit of a problem with this directory listing code, found
> it
> some time ago and have been modifying it.I have run up against one or
> two
> problems.
>
> 1\ How can I make it not list its self
> 2\ Is there away to specify what files it list
> 3\add a more clear back button
>
> My php is not that good and I have hit a wall so any help would be
> appreciated.
>
> Chris
>
> <?php
>  $allow_parent = "false";
>  $path=$_GET["path"];
>  $SCRIPT_NAME=getenv("SCRIPT_NAME");
>  if (!isset($path)) { $path = "./"; }
>  if (strstr($path,"..")) { echo "<h2>No path!</h2>"; exit; }
>  $base_dir = getcwd();
>  chdir($path);
>  $current_dir = getcwd();
>  $directory = dir("./");
>  $directories_array = array();
>  $files_array = array();
>  while ($file = $directory->read()) {

//I think you want this:
if ($file === '.' || $file === '..') continue;

>   if (is_dir($file) AND $file != ".")  { $directories_array[] = $file;
> }
>   if (is_file($file))    { $files_array[] = $file; }
>  }
>
>  $directory->close();
>  echo "";
>  echo "<table width=100% border=0 cellspacing=0 cellpadding=0>";
>  echo "<th>Name</th><th width=50>Size</th><th
> width=70>Date</th></tr>";
>  sort($directories_array);
>  foreach($directories_array as $value) {
>   if ($value=="..") {
> $new_path=strrev(substr(strstr(substr(strstr(strrev($path),"/"),1),"/"),1));
>  }
>   else   { $new_path=$path.$value; }
>   if (($value != "..") OR ($base_dir != $current_dir)) {
>    echo "<tr><td><font face=Verdana size=1><a
> href=\"$SCRIPT_NAME?path=".urlencode($new_path."/")."\"><b>$value</b></a></font></td><td></td><td><font
> face=Arial size=1>".gmdate("M
> Y",filemtime($value))."</font></td></tr>"; }
>   elseif ($allow_parent == "true") {
>    echo "<tr><td></td><td></td><td></td></tr>"; }
>  }
>  sort($files_array);
>  foreach($files_array as $value) {
>   if($value != basename($SCRIPT_NAME) or $path!="./") {
>    $filesize=filesize($value);
>    if  ($filesize > 1073741823) { $filesize =
> sprintf("%.1f",($filesize/1073741824))." GB"; }
>    elseif  ($filesize > 1048575)  { $filesize =
> sprintf("%.1f",($filesize/1048576))." MB"; }
>    elseif  ($filesize > 1023)  { $filesize =
> sprintf("%.1f",($filesize/1024))." kB"; }
>    else    { $filesize = $filesize." byte"; }
>    echo "<tr><td><font face=Verdana
> size=1><i>$value</i></font></td><td><font face=Arial
> size=1>$filesize</font></td><td><font face=Arial size=1>".gmdate("M
> Y",filemtime($value))."</font></td></tr>";
>   }
>  }
>  echo "</table>";
>  echo "";
>  echo "";
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux