PHP opendir() 函数
PHP 教程
· 2019-01-24 13:14:10
实例
打开一个目录,读取它的内容,然后关闭:
<?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);
}
}
?>
$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
filename: dog.gif
filename: horse.gif
定义和用法
opendir() 函数打开目录句柄。
语法
opendir(path,context);
| 参数 | 描述 |
|---|---|
| path | 必需。规定要打开的目录路径。 |
| context | 可选。规定目录句柄的环境。context 是可修改目录流的行为的一套选项。 |
技术细节
| 返回值: | 成功则返回目录句柄资源。失败则返回 FALSE。如果路径不是合法目录,或者由于许可限制或文件系统错误导致的目录不能打开,则抛出 E_WARNING 级别的错误。您可以通过在函数名称前添加 '@' 来隐藏 opendir() 的错误输出。 |
|---|---|
| PHP 版本: | 4.0+ |
| PHP 更新日志: | PHP 5.0:path 参数支持 ftp:// URL 封装协议。 |
点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html
100个可操作的网络赚钱方法
陶秋丰 / 云南科技 / 2009-12 / 29.80元
《100个可操作的网络赚钱方法》专为有志于网上创业的读者量身打造,作者是“实战型”的网赚高手,在17岁时就通过互联网创业“年人10万”,如今结合自身的亲身实战经验,与大家分享可以实实在在盈利的100个网络赚钱方法和技巧。内容包括:网站创建与推广、竞价广告、联盟赚钱、网站SEO优化、域名投资、广告投放盈利、威客、博客、淘客赚钱等多个方面。 本手册中作者结合自身的网络赚钱经历,通过具体的、可操作......一起来看看 《100个可操作的网络赚钱方法》 这本书的介绍吧!