Directory PHP核心函数
来源:互联网 发布:hishop 源码 编辑:程序博客网 时间:2024/05/20 13:19
1 chdir() 函数改变当前的目录。
语法:chdir(directory);directory 必需。规定新的当前目录。例:<?php// Get current directoryecho getcwd() . "<br>";// Change directorychdir("images");// Get current directoryecho getcwd();?>结果:/home/php/home/php/images
2 chroot() 函数改变当前进程的根目录为 directory,并把当前工作目录改为 “/”。
语法:chroot(directory);directory 必需。规定新的根目录路径。例:// Change root directorychroot("/path/to/chroot/");// Get current directoryecho getcwd();结果:/
3 closedir() 函数关闭目录句柄。
语法:closedir(dir_handle);dir_handle 可选。指定之前由 opendir() 打开的目录句柄资源。如果该参数未指定,则使用最后一个由 opendir() 打开的链接。例:$dir = "/images/";// Open a directory, and read its contentsif (is_dir($dir)){if ($dh = opendir($dir)){while (($file = readdir($dh)) !== false){echo "filename:" . $file . "<br>";}closedir($dh);}}结果:filename: cat.giffilename: dog.giffilename: horse.gif
4 dir() 函数返回 Directory 类的实例。该函数用于读取一个目录,包含如下:
给定的要打开的目录dir() 的 handle 和 path 两个属性是可用的handle 和 path 属性有三个方法:read()、rewind() 和 close()语法:dir(directory,context);directory必需。规定要打开的目录。context可选。例:$d = dir(getcwd());echo "Handle: " . $d->handle . "<br>";echo "Path: " . $d->path . "<br>";while (($file = $d->read()) !== false){ echo "filename: " . $file . "<br>"; } $d->close(); 结果:Handle: Resource id #2Path: /etc/phpfilename: .filename: ..filename: ajax.giffilename: books.xmlfilename: cdcatalog.xmlfilename: cd_catalog.xmlfilename: default.htmlfilename: demo_array.htmlfilename: demo_array.htm.........
5 getchwd() 函数返回当前工作目录。
语法:getcwd();例:echo getcwd()结果:/home/php
6 opendir() 函数打开目录句柄。
语法:opendir(path,context);path 必需。规定要打开的目录路径。context 可选。规定目录句柄的环境。context 是可修改目录流的行为的一套选项。例:$dir = "/images/";// Open a directory, and read its contentsif (is_dir($dir)){if ($dh = opendir($dir)){while (($file = readdir($dh)) !== false){echo "filename:" . $file . "<br>";}closedir($dh);}}结果:filename: cat.giffilename: dog.giffilename: horse.gif
7 readdir() 函数返回目录中下一个文件的文件名。
语法:readdir(dir_handle);dir_handle 可选。指定之前由 opendir() 打开的目录句柄资源。如果该参数未指定,则使用最后一个由 opendir() 打开的链接。例:$dir = "/images/";// Open a directory, and read its contentsif (is_dir($dir)){if ($dh = opendir($dir)){while (($file = readdir($dh)) !== false){echo "filename:" . $file . "<br>";}closedir($dh);}}结果:filename: cat.giffilename: dog.giffilename: horse.gif
8 rewinddir() 函数重置由 opendir() 创建的目录句柄。
语法:rewinddir(dir_handle);dir_handle 可选。指定之前由 opendir() 打开的目录句柄资源。如果该参数未指定,则使用最后一个由 opendir() 打开的链接。例:$dir = "/images/";// Open a directory, and read its contentsif (is_dir($dir)){if ($dh = opendir($dir)){// List files in images directorywhile (($file = readdir($dh)) !== false){echo "filename:" . $file . "<br>";}rewinddir();// List once again files in images directorywhile (($file = readdir($dh)) !== false){echo "filename:" . $file . "<br>";}closedir($dh);}}结果:filename: cat.giffilename: dog.giffilename: horse.giffilename: cat.giffilename: dog.giffilename: horse.gif
9 scandir() 函数返回指定目录中的文件和目录的数组。
语法:scandir(directory,sorting_order,context);directory 必需。规定要扫描的目录。sorting_order 可选。规定排列顺序。默认是 0,表示按字母升序排列。如果设置为 SCANDIR_SORT_DESCENDING 或者 1,则表示按字母降序排列。如果设置为 SCANDIR_SORT_NONE,则返回未排列的结果。context 可选。规定目录句柄的环境。context 是可修改目录流的行为的一套选项。例:$dir = "/images/";// Sort in ascending order - this is default$a = scandir($dir);// Sort in descending order$b = scandir($dir,1);print_r($a);print_r($b);结果:Array([0] => .[1] => ..[2] => cat.gif[3] => dog.gif[4] => horse.gif[5] => myimages)Array([0] => myimages[1] => horse.gif[2] => dog.gif[3] => cat.gif[4] => ..[5] => .)
0 0
- Directory PHP核心函数
- php核心函数xdebug_debug_zval
- PHP 5 Directory 函数
- php Directory
- PHP基于数组的分页函数(核心函数array_slice())
- PHP基于数组的分页函数(核心函数array_slice())
- PHP基于数组的分页函数(核心函数array_slice())
- PHP基于数组的分页函数(核心函数array_slice())
- CodeIgniter 核心代码阅读-公用函数文件Common.php
- php中glob();函数用户加载核心类或者配置文件
- PHP - Manual手册 - 函数参考 - Directory 目录函数 - scandir列出指定路径中的文件和目录
- php ----- directory 文件目录类
- PHP核心知识要点
- php核心知识点
- php核心知识点
- php核心知识点
- PHP核心知识点总结
- PHP核心配置详解
- bzoj1570: [JSOI2008]Blue Mary的旅行
- mysql数据库的安装
- apache commons collections CollectionUtils工具类简单使用
- 使用node过程中出现了乱码
- null的伟大与可怕 之 String字符串方法2
- Directory PHP核心函数
- 聊聊网站分析术语:PV、IP、UV
- 5-8 哈利·波特的考试 (最短路径——迪杰斯特拉算法)
- UE4旅程之VR项目打包设置
- 关于Java String类型的10个基本知识
- c# 反射在ORM中的应用
- spring boot jpa update 操作
- Kali中使用shadowsocks+proxychains实现任意应用代理
- Java小白之jar笔记