Home headlines PHP directory traversal operation

PHP directory traversal operation

Jun 28, 2018 am 11:01 AM

* 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 &#39;<hr>&#39;;
Copy after login

* 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(&#39;../0417/&#39;);
// print_r($fileArr);
foreach ($fileArr as $file) {
if ($file != "." && $file != "..") {
        echo "$file<br>";
     }
}
Copy after login

//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.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)