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

目录函数 chdir 改变目录

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

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

阅读全文 »

目录函数 chroot 改变根目录

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

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

阅读全文 »

目录函数 closedir 关闭目录句柄

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

      示例1
<?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);
    }
}
?>

阅读全文 »

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

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

      示例1
<?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();
?>

阅读全文 »

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

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

      示例1
<?php 
// current directory
echo getcwd() . "\n";
chdir('cvs');
// current directory
echo getcwd() . "\n";
?>

阅读全文 »

目录函数 opendir 打开目录句柄

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

      示例1
<?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);
    }
}
?>

阅读全文 »

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

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

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

阅读全文 »

目录函数 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
<?php 
$dir    = '/tmp';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);
print_r($files1);
print_r($files2);
?>

      示例2
<?php 
$dir = "/tmp";
$dh  = opendir($dir);
while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
}
sort($files);
print_r($files);
rsort($files);
print_r($files);
?>

阅读全文 »

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