PHP Implementation Bulk Empty Delete the contents of the specified folder in a detailed way

Source: Internet
Author: User
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);}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.