PHP readdir() 函数

PHP 教程 · 2019-01-24 13:29:13

实例

打开一个目录,读取它的内容,然后关闭:

<?php
$dir = "/images/";

// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>

结果:

filename: cat.gif
filename: dog.gif
filename: horse.gif

定义和用法

readdir() 函数返回目录中下一个文件的文件名。

语法

readdir(dir_handle);

参数 描述
dir_handle 可选。指定之前由 opendir() 打开的目录句柄资源。如果该参数未指定,则使用最后一个由 opendir() 打开的链接。

技术细节

返回值: 成功则返回文件名,失败则返回 FALSE。
PHP 版本: 4.0+

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Code Reading

Code Reading

Diomidis Spinellis / Addison-Wesley Professional / 2003-06-06 / USD 64.99

This book is a unique and essential reference that focuses upon the reading and comprehension of existing software code. While code reading is an important task faced by the vast majority of students,......一起来看看 《Code Reading》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

SHA 加密
SHA 加密

SHA 加密工具