菜单

PHP how to achieve batch empty delete all contents of the specified folder

2017年11月22日 - PHPer

This paper describes the PHP to achieve empty batch delete all the contents of the specified folder. To share with you for your reference, as follows:

Cleancache.php:

 

Code is as follows

<? PHP

/ / clear file cache

$dirs=array

Realpath (dirname (__FILE__).’/../data/cache_data’),

Realpath (dirname (__FILE__).’/../data/cache_file’),

Realpath (dirname (__FILE__).’/../data/cache_view’)

);

/ / clean cache

Foreach ($dirsas$dir) {

Do_rmdir ($dir, false);

Echo”

“”.$dir. “” have been cleaned clear!

“;

}

/ * *

* empty / delete folder

* @param string $dirname folder path

* @param bool $self to delete the current folder

* @return bool

.

Functiondo_rmdir ($dirname, $self= true) {

If (! File_exists ($dirname)) {

Returnfalse;

}

If (is_file ($dirname) ||is_link ($dirname)) {

Returnunlink ($dirname);

}

$dir= dir ($dirname);

(if $dir) {

(while ==$entry=$dir-> read (false!)) {

If ($entry==’.’||$entry==’..’) {

Continue;

}

Do_rmdir ($dirname.’/’.$entry);

}

}

($dir-> close);

$self& & rmdir ($dirname);

}

 

发表评论

电子邮件地址不会被公开。