php opendir()列出目录下所有文件的实例代码

PHP opendir()函数用于打开目录,通常与readdir()和closedir()函数一起用来读取目录下所有文件(即遍历目录),本文章向大家介绍PHP使用opendir()函数列出目录下所有文件的实例。

实例一:

使用opendir()列出目录下所有文件

rush:PHP;"> PHP

$dr = @opendir('/tmp/');
if(!$dr) {
echo "Error opening the /tmp/ directory!
";
exit;
}

while(($files[] = readdir($dr)) !== false);

print_r($files);
?>

实例二:

列出目录下所有文件

rush:PHP;"> PHP $dirname = "C:\\Apache\\bin"; $dir = opendir( $dirname );

while( false != ( $file = readdir( $dir ) ) )
{
if( ( $file != "." ) and ( $file != ".." ) )
{
$file_list .= "

  • $file
  • ";
    }
    }
    closedir( $dir );
    ?>

    <a href="https://www.jb51.cc/tag/liechumulu/" target="_blank" class="keywords">列出目录</a>下所有<a href="https://www.jb51.cc/tag/wenjian/" target="_blank" class="keywords">文件</a>

    Files in

    感谢阅读,希望能帮助到大家,谢谢大家对本站的支持

    相关文章

    统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
    统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
    前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
    FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
    之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
    统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...