The function imagecache_image_flush was not working for me:

function imagecache_image_flush($path) {
  $presets = _imagecache_get_presets();
  foreach($presets as $presetid => $presetname) {
    $path = file_directory_path() .'/imagecache/'. $presetname .'/'. $path;
    file_delete($preset_image);
  }
}

the file_delete variable is a typo. The correct function (that works for me) is:

function imagecache_image_flush($path) {
  $presets = _imagecache_get_presets();
  foreach($presets as $presetid => $presetname) {
    $path = file_directory_path() .'/imagecache/'. $presetname .'/'. $path;
    file_delete($path);
  }
}

Comments

jpsalter’s picture

the bug is also in 4.7.x-1.x-dev

quicksketch’s picture

Status: Active » Fixed

Thanks, this change must've been implemented in HEAD and 5 but not 4.7. I've corrected the function in the 4.7.x version.

jpsalter’s picture

And...

If you have more than one preset my "fixed" function will not work (the $path variable keeps growing). Here is my fix to delete multiple presets:

function imagecache_image_flush($path) {
  $presets = _imagecache_get_presets();
  foreach($presets as $presetid => $presetname) {
    $delete = file_directory_path() .'/imagecache/'. $presetname .'/'. $path;
    file_delete($delete);
  }
}
quicksketch’s picture

Thanks again. We used the exact same solution in 5 and HEAD (and now also 4.7).

function imagecache_image_flush($path) {
  $presets = _imagecache_get_presets();
  foreach($presets as $presetid => $presetname) {
    $ipath = file_directory_path() .'/imagecache/'. $presetname .'/'. $path;
    file_delete($ipath);
  }
}
Anonymous’s picture

Status: Fixed » Closed (fixed)