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
https://forums.phpfreaks.com/topic/20263-list-files/#findComment-89169
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
https://forums.phpfreaks.com/topic/20263-list-files/#findComment-89326
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
https://forums.phpfreaks.com/topic/20263-list-files/#findComment-89329
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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