PHP directory traversal operation
* Directory traversal operation:
* 1. Traditional process functions: opendir(), readdir(), closedir()
* 2. Directory scanner: scandir()
* The first way: traditional directory function
* The first step: opendir('directory') opens the directory, returns the resource successfully, returns false on failure
* The second step : readdir($dir) reads the directory content, Shigong returns the file name, and returns false on failure
* The third step: closedir($dir) closes the current directory
$dir = opendir('../0418') or die('打开失败'); // $dir = opendir('./') or die('打开失败'); //.或./当前目录 while (false != ($file = readdir($dir))) { // print $file."<br>"; // print nl2br($file."\n"); if ($file != "." && $file != "..") { print $file."<br>"; } } closedir($dir); echo '<hr>';
* The second type Method: Save the directory contents into an array for traversal
* The first step: scandir($dir) converts the directory into an array and saves it
* The second step: Traverses the directory array
//Read the contents of a directory into an array:
$fileArr = scandir('../0417/'); // print_r($fileArr); foreach ($fileArr as $file) { if ($file != "." && $file != "..") { echo "$file<br>"; } }
//Explanation: If you want to recurse all directories, you need to write a custom function to solve the problem. We introduce a more convenient recursive traversal technology.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

