详细介绍PHP读取目录函数
我们在这里为大家介绍的是
- ?php
- $base_dir = "filelist/";
- $fso = opendir($base_dir);
- echo $base_dir." hr/>" ;
- while($flist=readdir($fso)){
- echo $flist." br/>" ;
- }
- closedir($fso)
- ?>
这是讲返回文件目录下面的文件已经目录的程序(0文件将返回false).
有时候PHP读取目录函数需要知道目录的信息,可以使用dirname($path)和basename($path),分别返回路径的目录部分和文件名名称部分,可用disk_free_space($path)返回看空间空余空间.
创建命令:
mkdir($path,0777)
,0777是权限码,在非window下可用umask()函数设置.
rmdir($path)
将删除路径在$path的文件.
dir -- directory 类也是操作文件目录的重要类,有3个方法,read,rewind,close,这是一个仿面向对象的类,它先使用的是打开文件句柄,然后用指针的方式读取的.,这里看php手册是怎么描述PHP读取目录函数的:
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><span> ?php </span></span></span></li> <li> <span>$</span><span class="attribute">d</span><span> = </span><span class="attribute-value">dir</span><span>("/etc/php5"); </span> </li> <li class="alt"> <span>echo "Handle: " . <br>$d-</span><span class="tag">></span><span>handle . "n"; </span> </li> <li> <span>echo "Path: " . <br>$d-</span><span class="tag">></span><span>path . "n"; </span> </li> <li class="alt"> <span>while (false !== <br>($</span><span class="attribute">entry</span><span> = $d-</span><span class="tag">></span><span>read())) { </span> </li> <li><span>echo $entry."n"; </span></li> <li class="alt"><span>} </span></li> <li> <span>$d-</span><span class="tag">></span><span>close(); </span> </li> <li class="alt"> <span class="tag">?></span><span> </span> </li> <li><span> </span></li> </ol>
输出:
Handle: Resource id #2
Path: /etc/php5
.
..
apache
cgi
cli
文件的属性对于PHP读取目录函数也非常重要,文件属性包括创建时间,最后修改时间,所有者,文件组,类型,大小等.

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

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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