加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-12 21:45:20 所属栏目:PHP教程 来源:网络整理
导读:php opendir()函数用于打开目录,通常与readdir()和closedir()函数一起用来读取目录下所有文件(即遍历目录),本文章向大家介绍php使用opendir()函数列出目录下所有文件的实例。 实例一: 使用opendir()列出目录下所有文件 $dr = @opendir('/tmp/'); if(!$dr)

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

实例一:

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

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

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

print_r($files);
?>

实例二:

列出目录下所有文件

while( false != ( $file = readdir( $dir ) ) )
{
if( ( $file != "." ) and ( $file != ".." ) )
{
$file_list .= "
  • $file
  • ";
    }
    }
    closedir( $dir );
    ?>

    列出目录下所有文件

    Files in

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

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读