PHP rewinddir() 函數
實例
打開一個目錄,列出其中的檔,充值目錄句柄,重新列出其中的檔,然後關閉:
<?php
$dir = "/images/";
// Open a directory, and read its contents
if (is_dir($dir)){
if ($dh = opendir($dir)){
// List files in images directory
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
rewinddir();
// List once again files in images directory
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)){
// List files in images directory
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
rewinddir();
// List once again files in images directory
while (($file = readdir($dh)) !== false){
echo "filename:" . $file . "<br>";
}
closedir($dh);
}
}
?>
結果:
filename: cat.gif
filename: dog.gif
filename: horse.gif
filename: cat.gif
filename: dog.gif
filename: horse.gif
filename: dog.gif
filename: horse.gif
filename: cat.gif
filename: dog.gif
filename: horse.gif
定義和用法
rewinddir() 函數重置由 opendir() 創建的目錄句柄。
語法
rewinddir(dir_handle);
參數 | 描述 |
---|---|
dir_handle | 可選。指定之前由 opendir() 打開的目錄句柄資源。如果該參數未指定,則使用最後一個由 opendir() 打開的鏈接。 |
技術細節
返回值: | - |
---|---|
PHP 版本: | 4.0+ |
