删除操作,平日里面多见于网盘。通过删除操作,我们可以批量地完成删除多文件的一个任务。说到批量删除,那就不得不提到批量获取给定目录下面的目录路径了。删除文件呢,遍历是一个非常之必要的过程,没有遍历就没有办法获取相应的文件路径,才能准确地删除
删除操作,平日里面多见于网盘。通过删除操作,我们可以批量地完成删除多文件的一个任务。说到批量删除,那就不得不提到批量获取给定目录下面的目录路径了。删除文件呢,遍历是一个非常之必要的过程,没有遍历就没有办法获取相应的文件路径,才能准确地删除掉目录下面的文件。而我们应该怎么去获取目录下面所有子目录的路径呢,这也算是一个比较关键的一点哦。下面我直接上代码了:这里用到的函数是glob,返回的将是一个数组!!
代码
<?php ? ?? function?getDirs($directory){? ?? ????$opt?=?array();? ?? ????foreach(glob(str_replace("//","/","$directory/*"),GLOB_ONLYDIR)?as?$dir){? ?? ????????$opt[]?=?str_replace($directory,"",$dir);? ?? ????}? ?? ????return?$opt;? ?? }? ?? //获取顶级目录的所有目录?也就是这个文件所在目录的同级目录?然后把数组打印出来 ?? print_r(getDirs('../'));? ?? ?>??
声明: 本文采用 BY-NC-SA 协议进行授权 | IT路人
转载请注明转自《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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version
SublimeText3 Linux latest version
