Location: PHPKode > scripts > FarODP > farodp/cache-tool.php
<?php

/////////////////////////////////////////////////////////////
// version 1.1.4
// change 'password' to anything different to run this script

$user_password='password';

/////////////////////////////////////////////////////////////

//===========================================================
// NO MODIFYING BELOW (unless you know what you're doing)
//===========================================================

$post_password = isset($_POST['password']) ? $_POST['password'] : '';

$delete_folder = isset($_POST['delete']) ? $_POST['delete'] : '';

$cache_folder='./cache/';

$time_days=isset($_POST['time']) ? $_POST['time'] : 0;

if ($time_days=='')
{
	$time_days=0;
}

$time=$time_days*86400;

$current_time=time();

$size=0;

$num_files=0;

function get_dir_size($dir)
{
	global $size, $num_files;
	if (is_dir($dir))
	{
		if ($dh=opendir($dir))
		{
			while (($file=readdir($dh))!==false)
			{
				$size+=filesize($dir.$file);
				$num_files++;
			}
			closedir($dh);
		}
	}
}

function deldir($dir)
{
	global $current_time, $time;
	if (empty($dir))
	{
		echo '<font color="#ff0000"><b>cache folder has no name</b></font><br />';
		return;
	}
	$handle=opendir($dir);
	while ($file=readdir($handle))
	{
		if($file!="." && $file!="..")
		{
			$fullpath=$dir."/".$file;
			if ($current_time-filemtime($fullpath)>$time)
			{
				if(is_dir($fullpath))
				{
					deldir($fullpath);
				}
				else
				{
					unlink($fullpath);
				}
			}
		}
	}
}

if ($user_password=='password')
{
	$content='<font color="#ff0000"><b>You must modify this file to get a password.</b></font><br />';
}
elseif ($post_password!=$user_password && $user_password!='password')
{
	$content='Please enter your password.<br />';
}
elseif ($post_password==$user_password && $user_password!='password')
{
	$content='';
	deldir($cache_folder);
}
else
{
	$content='Error in this file.';
}
$num_files=$num_files-2; // It always counts two files more than the number of files
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ODP Cache Deleter</title>
</head>
<body onload="document.cache.password.focus()">
<h1>ODP Cache Deleter</h1>
Type in a password to empty the cache folder.<br />
<?php echo $content;
get_dir_size($cache_folder); ?>
Total size of cache folder: <?php echo round($size/1048576,2); ?> mb<br />
<?php
if ($num_files>0)
{
?>
	Number of files: <?php echo $num_files; ?><br />
	Average file size: <?php echo round(($size/$num_files)/1024,2); ?> kb<br />
<?php
}
?>
<form name="cache" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Password: <input type="password" name="password" /><br />
Delete all cached files that are created older than: <input type="text" name="time" /> days. (Leave it blank or type in a 0 to delete all cached files)<br />
<input type="submit" name="delete" value="Delete Cache" />
</form>
</body>
</html>
Return current item: FarODP