建站极客
网络编程 PHP编程 正文
兼容PHP5的PHP目录管理函数库
所属分类:
网络编程 / PHP编程
阅读数:
906
收藏 0
赞 0
分享
主要能兼容: PHP 5 一、chdir -- 改变目录 语法:bool chdir ( string directory ) 返回值:整数 函数种类: 文件存取 内容说明: 将 PHP 的当前目录改为directory。directory:新的当前目录。返回值如果成功则返回 TRUE,失败则返回 FALSE。 例子讲解: 程序代码 <?php // current directory echo getcwd() . "\n"; chdir('public_html'); // current directory echo getcwd() . "\n"; ?> 输出结果为: /home/vincent /home/vincent/public_html 注意:循环语句中会出现“ Warning: chdir(): No such file or directory (errno 2) in ***** on line *”错误。 程序代码 <?php // current directory echo getcwd() . "\n"; for($i=1; $i<=2; $i++){ chdir('whoist'); // current directory echo getcwd() . "\n"; } ?> 二、dir -- directory 类 语法:new dir(string directory); 返回值:类 函数种类: 文件存取 内容说明: 这是一个类似面向对象的类别类,用来读取目录。当目录参数 directory 打开之后,有二个属性可用:handle 属性就像其它非类的函数所用的 readdir()、rewinddir() 及 closedir();path 属性则配置打开目录后的路径参数。本类有三个方法 (method):read、rewind 与 close。 class dir { dir ( string directory ) string path resource handle string read ( void ) void rewind ( void ) void close ( void ) } 例子讲解: 程序代码 <?php $d = dir("/etc/php5"); echo "Handle: " . $d->handle . "\n"; echo "Path: " . $d->path . "\n"; while (false !== ($entry = $d->read())) { echo $entry."\n"; } $d->close(); ?> 输出结果为: Handle: Resource id #2 Path: /etc/php5 . .. apache cgi cli 注: read 方法返回的目录项的顺序依赖于系统。 注: 本函数定义了内部类 Directory,意味着不能再用同样的名字定义用户自己的类。 三、closedir -- 关闭目录句柄 语法:void closedir ( resource dir_handle ) 返回值:无 函数种类: 文件存取 内容说明: 关闭由 dir_handle 指定的目录流。流必须之前被 opendir() 所打开。 例子讲解: 程序代码 <?php $dir = "/etc/php5/"; // Open a known directory, read directory into variable and then close if (is_dir($dir)) { if ($dh = opendir($dir)) { $directory = readdir($dh); closedir($dh); } } ?> 四、opendir -- 打开目录句柄 语法:resource opendir ( string path [, resource context] ) 返回值:整数 函数种类: 文件存取 内容说明: 本函数用来打开目录资料流。返回的整数是可供其它目录函数closedir(),readdir() 和 rewinddir() 操作的 handle。如果成功则返回目录句柄的resource,失败则返回 FALSE。 例子讲解: 程序代码 <?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); } } ?> 输出结果为: filename: . : filetype: dir filename: .. : filetype: dir filename: apache : filetype: dir filename: cgi : filetype: dir filename: cli : filetype: dir
PHP利用Mysql锁解决高并发的方法 这篇文章主要介绍了PHP利用Mysql锁解决高并发的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
评论 0
收藏 0
赞 0
分享
php 后端实现JWT认证方法示例 这篇文章主要介绍了php 后端实现JWT认证方法示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
评论 0
收藏 0
赞 0
分享
PHP命名空间与自动加载类详解 这篇文章主要介绍了PHP命名空间与自动加载类,结合实例形式详细分析了php自动加载类与命名空间原理、使用方法及相关操作注意事项,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
PHP时间处理类操作示例 这篇文章主要介绍了PHP时间处理类,结合实例形式分析了DateTime、DateTimeZone、DateInterval及DatePeriod等常用日期时间处理类简单操作技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
利用PHP扩展Xhprof分析项目性能实践教程 XHProf是Facebook开发的性能调试工具,能帮助直观的统计显示PHP程序执行中各方法函数调用次数和消耗时间,以方便我们排查性能瓶颈并进行调优。下面这篇文章主要给大家介绍了关于利用PHP扩展Xhprof分析项目性能实践的相关资料,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
PHP使用pdo实现事务处理操作示例 这篇文章主要介绍了PHP使用pdo实现事务处理操作,结合实例形式较为详细的分析了php基于pdo实现事务处理的相关原理与操作技巧,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
查看更多