Skip to content

Instantly share code, notes, and snippets.

@withremote
Created March 13, 2013 17:34
Show Gist options
  • Save withremote/5154366 to your computer and use it in GitHub Desktop.
Save withremote/5154366 to your computer and use it in GitHub Desktop.
codeigniter-cache delete_all()
/**
* Delete Full Cache or Cache subdir
* Skips .htaccess and index.htm(l) files for security
*
* @access public
* @param string
* @return void
*/
function delete_all($dirname = '')
{
if (empty($this->_path))
{
return FALSE;
}
$this->_ci->load->helper('file');
if (file_exists($this->_path.$dirname)) {
$files = scandir($this->_path.$dirname);
foreach($files as $f) {
if($f != '.' && $f != '..' && $f != '.htaccess' && strpos($f, 'index.htm') === false) {
$p = str_replace('\\','/', rtrim($this->_path.$dirname,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$f);
if(is_dir($p)) {
delete_files($p, TRUE);
rmdir($p);
} else {
unlink($p);
}
}
}
}
// Reset values
$this->_reset();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment