The example in this article describes the method of reading all file names in a directory and subdirectories in PHP and shares it with you for your reference. The specific implementation method is as follows:
Generally speaking, there are many ways to read file names in a directory in PHP. The simplest one is scandir. The specific code is as follows:
The slightly more complicated one comes from the php manual:
These can only read files in the currently specified directory, but cannot read files in subdirectories. It turned out that I had written a piece of code to delete all directories in a loop. I needed to delete all files in subdirectories one by one, including multiple layers. But you only need to read out the file name, which is a little more complicated. I found one online that works. The original code has an error message. I changed the reference to &$data as follows:
function getDir($dir){
$data=array();
searchDir($dir,$data);
return $data;
}
print_r(getDir('.'));
I hope this article will be helpful to everyone’s PHP programming design.