search
Homephp教程php手册php删除指定目录下的的文件/文件夹-用PHP怎么删除某目录下指定的一个文件/文件夹?

 

1

 2     $dir = '你要删除的目录路径';    //如下:

 3     //$dir = $_SERVER['DOCUMENT_ROOT'].'/cache';

 4     rmdirs($dir);

 5    

 6     //php删除指定目录下的的文件-用PHP怎么删除某目录下指定的一个文件?

 7     function rmdirs($dir){

 8         //error_reporting(0);    函数会返回一个状态,我用error_reporting(0)屏蔽掉输出

 9         //rmdir函数会返回一个状态,我用@屏蔽掉输出

10         $dir_arr = scandir($dir);

11         foreach($dir_arr as $key=>$val){

12             if($val == '.' || $val == '..'){}

13             else {

14                 if(is_dir($dir.'/'.$val))   

15                 {                           

16                     if(@rmdir($dir.'/'.$val) == 'true'){}    //去掉@您看看                

17                     else

18                     rmdirs($dir.'/'.$val);                   

19                 }

20                 else               

21                 unlink($dir.'/'.$val);

22             }

23         }

24     }   

25 ?>

php删除指定目录下的文件夹和文件-用PHP怎么删除某目录下指定的一个文件夹和文件?

作者 网宗

Statement
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

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

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.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.