Here's one that I put together.  It's browseable and easy on the eyes.  It's
not the prettiest code but it works. 

<?
// I have PHP 4.1.0 which needs this
error_reporting(E_ERROR);

// path to your web root (don't put trailing slash /)
$web_path = "/inetpub/wwwroot";

// If they try to get to the root directory redirect them to $web_path
if ($path == "/"):
        $path = "";
endif;

// If the directory doesn't exist redirect them to $web_path
if (!file_exists("$web_path" . "$path")):
        $path = "";     
endif;

$dir = opendir("$web_path" . "$path");

// Print the $file_name (s)
$msg = "<table width=\"600\">
        <tr>
        <td valign=\"top\" bgcolor=\"#C6C6FF\"><B>Files in
$web_path$path</b></td></tr>
        <tr><td>&nbsp;</td></tr>
        <tr>
        <td valign=\"top\"><ul>\n";
        while ($file_name = readdir($dir)):
                // Check to see if it's a directory.
                $is_dir = is_dir("$web_path" . "$path/$file_name");
                // Skip if the file_name returned is "." or ".."
              if (($file_name != ".") && ($file_name != "..")):
                // If it's not a directory then add it to the $files
variable and assign it class=file (this class we put in the style.css)
                if ($is_dir != "1"):
                        $files .= "<li class=\"file\"><a
href=\"$path/$file_name\" target=\"blank\"
                                title=\"View $file_name\">$file_name</a>\n";
                else:
                // If it's not a directory then add it to the $folders
variable and assign it class=dir (this class we put in the style.css)
                        $folders .= "<li class=\"dir\"><a
href=\"$PHP_SELF?path=$path/$file_name\"
                                title=\"Go to $file_name
directory\">$file_name</a>\n";
                // End if ($is_dir)
                endif;
        // End if (($file_name != ".") && ($file_name != ".."))
              endif;
        // End while reading directory
        endwhile;

// Put the $folders and $files variables together so folders show up first.
$msg .= $folders . $files;

// If there's no list items then the dir is empty.
        if ((preg_match("/<li class=\"file/", $msg)) || (preg_match("/<li
class=\"dir/", $msg))): 
              $msg .= "</ul>";
        else:
              $msg .= "</ul><P>This directory is empty.</p>";
        endif;

              $msg .= "<P><a
href=\"Javascript:history.go(-1)\">Back</a></p></td></tr>
                        </table>";

              closedir($dir);
?>
<html>
<head>
<title>Browse Files in <? echo "$web_path" . "$path"; ?></title>
<link rel="stylesheet" href="/style.css" type="text/css">
</head>
<body>
<? echo $msg; ?>
</body>
</html>

Here's the contents of style.css

li.dir { list-style: url(/images/folder.gif) disc }
li.file { list-style: url(/images/file.gif) disc }

I attached file.gif and folder.gif.

Hope this helps.

v/r,
NATHAN BROWNING, SrA, USAF
509 CS/SCNO  NCC Operations
DSN 975-5267  Comm (660) 687-5267
"The real art of conversation is not only to say the right thing at the
right time, but also to leave unsaid the wrong thing at the tempting
moment."

-----Original Message-----
From: Phil Huynh [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 10, 2002 8:29 AM
Cc: [EMAIL PROTECTED]
Subject: [PHP-INST] display the file in directory



Hi,
    I am trying to read the files in the directory and display them .
but I got the message " the document contain no data "

this is my code
<?
  $d = dir("/export/home/phuy/www/test/upload");
  echo "Handle: ".$d->handle."<br>";
  echo "Path: ".$d->path."<br>";

  while($entry=$d->read()) {
echo $entry."<br>\n";
  }
  echo "<hr>";
  $d->close();
?>

  Can anyone tell me what should I do to correct it.
  I would like some help, thank in advance.



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


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

Reply via email to