Detailed example of php reading all files in a folder

零下一度
Release: 2023-03-10 15:42:02
Original
2424 people have browsed it

This article mainly introduces the method of php to read out all the files in a folder and its subfolders, involving phprecursionand 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; }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!