This article mainly introduces the method of php to read out all the files in a folder and its subfolders, involving phprecursion and file path related operation skills. Friends in need can refer to the following
The example in this article describes how PHP reads out all the files in a folder and its subfolders. Share it with everyone for your reference. The details are as follows:
Today’s requirement is to read out all the files under this folder in a folder, including of course all the subfolders under this folder. Of course There are many tutorials on the Internet, but in order to understand it more deeply, it is better to write it yourself. The code is as follows:
$path = './use'; $result = scanFile($path); function scanFile($path) { global $result; $files = scandir($path); foreach ($files as $file) { if ($file != '.' && $file != '..') { if (is_dir($path . '/' . $file)) { scanFile($path . '/' . $file); } else { $result[] = basename($file); } } } return $result; }
The above is the detailed content of Detailed example of php reading all files in a folder. For more information, please follow other related articles on the PHP Chinese website!