This article mainly introduces the PHP implementation of bulk emptying delete all the contents of the specified folder method, involving PHP based on a custom function recursive call implementation to delete files in the specified directory and folder-related operations skills, the need for friends can refer to the next
This article explains how PHP implements bulk emptying to delete all contents of a specified folder. Share to everyone for your reference, as follows:
cleancache.php:
<?php//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 ($dirs as $dir) {Do_rmdir ($dir, false); echo "<p style= ' border:2px solid green; Background: #f1f1f1; Padding:20px;margin:20px;width:800px;font-weight:bold;color:green;text-align:center; ' >\ "". $dir. "\" has been cleaned clear! </p> ";} /** * Empty/Delete folder * @param string $dirname folder path * @param bool $self Whether to delete the current folder * @return bool */function do_rmdir ($dirname, $self = True) {if (!file_exists ($dirname)) {return false; } if (Is_file ($dirname) | | is_link ($dirname)) {return unlink ($dirname); } $dir = Dir ($dirname); if ($dir) {while (false!== $entry = $dir->read ()) {if ($entry = = '. ' | | $entry = = ' ... ') {continue; } do_rmdir ($dirname. '/' . $entry); }} $dir->close (); $self && rmdir ($dirname);}