Tools, FAQ, Tutorials:
Reading Directory Entries in PHP
How To Read a Directory One Entry at a Time in PHP?
✍: FYIcenter.com
If you want to read a directory one entry at a time, you can use opendir() to open the specified directory to create a directory handle, then use readdir() to read the directory contents through the directory handle one entry at a time. readdir() returns the current entry located by the directory pointer and moves the pointer to the next entry. When end of directory is reached, readdir() returns Boolean false. Here is a PHP script example on how to use opendir() and readdir():
<?php
mkdir("/temp/download");
$array["one"] = "Download PHP scripts at dev.fyicenter.com.\r\n";
$array["two"] = "Download Perl scripts at dev.fyicenter.com.\r\n";
$bytes = file_put_contents("/temp/download/todo.txt", $array);
print("List of files:\n");
$dir = opendir("/temp/download");
while ( ($file=readdir($dir)) !== false ) {
print("$file\n");
}
closedir($dir);
?>
This script will print:
List of files: . .. todo.txt
⇒ Retrieving Directory Name from File Path Name in PHP
⇐ Putting Directory Entries into an Array in PHP
2016-11-20, ∼2473🔥, 0💬
Popular Posts:
How To Get the Minimum or Maximum Value of an Array in PHP? If you want to get the minimum or maximu...
Can Two Forms Be Nested? Can two forms be nested? The answer is no and yes: No. You can not nest two...
How to use "xsl-transform" Azure API Policy Statement? The "xsl-transform" Policy Statement allows y...
Where to find tutorials on PHP language? I want to know how to learn PHP. Here is a large collection...
How To Change Text Fonts for Some Parts of a Paragraph? If you want to change text fonts or colors f...