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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SecLists

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.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool