How to achieve unlimited directory traversal in PHP development (code example)
在php开发中,我们会经常遇到各种各样的难题,想要实现php无限遍历目录,可就很难实现这一方法,经过在网上查询一些资料,阅读一些论坛,才发现php无限遍历目录并没有想象那么难,现在就看一下吧。
使用的函数有:
isset()判断某个变量是否定义
chdir() 将当前目录改变为指定的目录。
opendir() 打开目录。
readdir()读取目录。
getcwd()。获取当前目录。
还用到了for if GET传值 大概就这些东东:
下面是代码:
<?php if(isset($_GET['id']))//判断是否传值 { $s=str_replace(' ','+',$_GET['id']); $s=base64_decode($s);//接受传递的值 值一般是要打开的目录的绝对路劲 chdir($s);//切换到要打开的目录 } $a=opendir('.');//打开当前目录 while(false!==($c=readdir($a)))//循环遍历目录内容的文件名 { if(is_dir($c))//判断是目录还是文件 { if($c=='.') { } else { if($c=='..') { $w=base64_encode(substr(getcwd(),0,strrpos(getcwd(),'\\')));//当前路径加上目录名 就是目录的绝对路径 echo "上一级"."<a href="http://www.php1.cn/"> }else { $w=base64_encode(getcwd().'\\'.$c);//当前路径加上目录名 就是目录的绝对路径 echo "$c"."<a href="http://www.php1.cn/"> } } } else { echo "$c 不是目录<br />"; } } ?>
Copy after login
以上就是php无限遍历目录的全部内容,大家在学习的时候需要注意一个问题,就是路径一定要是绝对路径,千万不要弄错了,希望能帮助到大家。
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
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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
How to fix KB5055612 fails to install in Windows 10?
4 weeks ago
By DDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks ago
By DDD
Nordhold: Fusion System, Explained
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

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
Java Tutorial
1672
14


CakePHP Tutorial
1428
52


Laravel Tutorial
1332
25


PHP Tutorial
1277
29


C# Tutorial
1257
24

