Jump to content

list files


GeorgeMoney

Recommended Posts

straight from the source:

[url=http://us3.php.net/manual/en/function.opendir.php]http://us3.php.net/manual/en/function.opendir.php[/url]


[code]
<?php
$dir = "/etc/php5/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
  if ($dh = opendir($dir)) {
      while (($file = readdir($dh)) !== false) {
          echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
      }
      closedir($dh);
  }
}
?>
[/code]

Jeff
Link to comment
Share on other sites

Try this if you use a version >= PHP 5.

[code=php:0]<?php
$dir = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator('.' . DIRECTORY_SEPARATOR)
);

foreach ($dir as $file) {
    printf(
        '%s %s is a %s' . PHP_EOL,
        str_repeat(' ', $dir->getDepth()),
        $file,
        $file->getType()
    );
}
?>[/code]

Regards, Ben.
Link to comment
Share on other sites

[code]
<?php
$dir_name = "uploads/";
$dir = opendir($dir_name);

$file_list = "<ol>";
while ($file_name = readdir($dir)){

if (($file_name != ".") && ($file_name != "..")) {
$file_list .= "<li><a href=\"uploads/".$file_name."\">".$file_name;
echo "</a>";
}
}

$file_list .= "</ol>";
closedir($dir);
echo "<div align=\"left\">";
echo "The files currently uploaded are as follows:<br />".$file_list;
echo "</div>";
?>[/code]

that also makes each item in the list a link to that item
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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