You are here

function _imagecache_recursive_delete in ImageCache 6.2

Same name and namespace in other branches
  1. 5.2 imagecache.module \_imagecache_recursive_delete()
  2. 5 imagecache.module \_imagecache_recursive_delete()

Recursively delete all files and folders in the specified filepath, then delete the containing folder.

Note that this only deletes visible files with write permission.

Parameters

string $path: A filepath relative to file_directory_path.

3 calls to _imagecache_recursive_delete()
imagecache_drush_preset_flush in ./imagecache.drush.inc
Drush callback to perform actual imagecache preset flush.
imagecache_preset_flush in ./imagecache.module
Flush cached media for a preset.
imagecache_uninstall in ./imagecache.install
Implementation of hook_uninstall().

File

./imagecache.module, line 842
Dynamic image resizer and image cacher.

Code

function _imagecache_recursive_delete($path) {
  if (is_file($path) || is_link($path)) {
    unlink($path);
  }
  elseif (is_dir($path)) {
    $d = dir($path);
    while (($entry = $d
      ->read()) !== FALSE) {
      if ($entry == '.' || $entry == '..') {
        continue;
      }
      $entry_path = $path . '/' . $entry;
      _imagecache_recursive_delete($entry_path);
    }
    $d
      ->close();
    rmdir($path);
  }
  else {
    watchdog('imagecache', 'Unknown file type(%path) stat: %stat ', array(
      '%path' => $path,
      '%stat' => print_r(stat($path), 1),
    ), WATCHDOG_ERROR);
  }
}