Tools, FAQ, Tutorials:
Putting Directory Entries into an Array in PHP
How To Dump the Contents of a Directory into an Array in PHP?
✍: FYIcenter.com
If you want to get the contents of a directory into an array, you can use the scandir() function. It gets a list of all the files and sub directories of the specified directory and returns the list as an array. The returning list also includes two specify entries: (.) and (..). Here is a PHP script example on how to use scandir():
<?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);
$files = scandir("/temp/download");
print_r($files);
?>
This script will print:
Array
(
[0] => .
[1] => ..
[2] => todo.txt
)
⇒ Reading Directory Entries in PHP
2016-11-20, ∼2481🔥, 0💬
Popular Posts:
How to create a navigation file like navigation.xhtml for an EPUB 3.0 book? At least one navigation ...
Where to find tutorials on OpenID? Here is a large collection of tutorials to answer many frequently...
How To Read the Entire File into a Single String in PHP? If you have a file, and you want to read th...
How to pull NVIDIA CUDA Docker Image with the "docker image pull nvidia/cuda" command? If you are ru...
How to use "json-to-xml" Azure API Policy Statement? The "json-to-xml" Policy Statement allows you t...