目录函数 业 ,精于勤 荒于嬉.

目录函数 chdir 改变目录

发表日期:2021-07-01 08:55:30 | 来源: | 分类:目录函数

      示例1
1<?php 
2// current directory
3echo getcwd() . "\n";
4chdir('public_html');
5// current directorye
6cho getcwd() . "\n";
7?>

阅读全文 »

目录函数 chroot 改变根目录

发表日期:2021-07-01 08:55:30 | 来源: | 分类:目录函数

      示例1
1<?php
2chroot("/path/to/your/chroot/");
3echo getcwd();
4?>

阅读全文 »

目录函数 closedir 关闭目录句柄

发表日期:2021-07-01 08:55:31 | 来源: | 分类:目录函数

      示例1
01<?php 
02$dir "/etc/php5/";
03// Open a known directory, read directory into variable and then close
04if (is_dir($dir)) {
05    if ($dh = opendir($dir)) {
06        $directory = readdir($dh);
07        closedir($dh);
08    }
09}
10?>

阅读全文 »

目录函数 dir 返回一个 Directory 类实例

发表日期:2021-07-01 08:55:31 | 来源: | 分类:目录函数

      示例1
1<?php
2$d = dir("/etc/php5");
3echo "Handle: " $d->handle . "\n";
4echo "Path: " $d->path . "\n";
5while (false !== ($entry $d->read())) {
6   echo $entry."\n";
7}
8$d->close();
9?>

阅读全文 »

目录函数 getcwd 取得当前工作目录

发表日期:2021-07-01 08:55:31 | 来源: | 分类:目录函数

      示例1
1<?php 
2// current directory
3echo getcwd() . "\n";
4chdir('cvs');
5// current directory
6echo getcwd() . "\n";
7?>

阅读全文 »

目录函数 opendir 打开目录句柄

发表日期:2021-07-01 08:55:30 | 来源: | 分类:目录函数

      示例1
01<?php 
02$dir "/etc/php5/";
03// Open a known directory, and proceed to read its contents
04if (is_dir($dir)) {
05    if ($dh = opendir($dir)) {
06        while (($file = readdir($dh)) !== false) {
07            echo "filename: $file : filetype: " filetype($dir $file) . "\n";
08        }
09        closedir($dh);
10    }
11}
12?>

阅读全文 »

目录函数 readdir 从目录句柄中读取条目

发表日期:2021-07-01 08:55:30 | 来源: | 分类:目录函数

      示例1
01<?php 
02// 注意在 4.0.0-RC2 之前不存在 !== 运算符
03if ($handle = opendir('/path/to/files')) {
04    echo "Directory handle: $handle\n";
05    echo "Files:\n";
06    /* 这是正确地遍历目录方法 */
07    while (false !== ($file = readdir($handle))) {
08        echo "$file\n";
09    }
10    /* 这是错误地遍历目录的方法 */
11    while ($file = readdir($handle)) {
12        echo "$file\n";
13    }
14    closedir($handle);
15}
16?>
      示例2
01<?php 
02if ($handle = opendir('.')) {
03    while (false !== ($file = readdir($handle))) {
04        if ($file != "." && $file != "..") {
05            echo "$file\n";
06        }
07    }
08    closedir($handle);
09}
10?>

阅读全文 »

目录函数 rewinddir 倒回目录句柄

发表日期:2021-07-01 08:55:31 | 来源: | 分类:目录函数

rewinddir

(PHP 4, PHP 5, PHP 7, PHP 8)

rewinddir倒回目录句柄

说明

rewinddir(resource $dir_handle): void

dir_handle 指定的目录流重置到目录的开头。

参数

dir_handle

目录句柄的 resource,之前由 opendir() 打开

阅读全文 »

目录函数 scandir 列出指定路径中的文件和目录

发表日期:2021-07-01 08:55:31 | 来源: | 分类:目录函数

      示例1
1<?php
2$dir    '/tmp';
3$files1 = scandir($dir);
4$files2 = scandir($dir, 1);
5print_r($files1);
6print_r($files2);
7?>
      示例2
01<?php
02$dir "/tmp";
03$dh  = opendir($dir);
04while (false !== ($filename = readdir($dh))) {
05    $files[] = $filename;
06}
07sort($files);
08print_r($files);
09rsort($files);
10print_r($files);
11?>

阅读全文 »

全部博文(1589)
集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。