echo 'yellow;">"phpThumb.config.php" not found (nor "phpThumb.config.php")';
}
echo '</th><td>"phpThumb.config.php.default" that comes in the distribution must be renamed to "phpThumb.config.php" before phpThumb.php can be used. Avoid having both files present to minimize confusion.</td></tr>';
echo '<tr><th>cache directory:</th><th colspan="2">';
$orig_config_cache_directory = $phpThumb->config_cache_directory;
$phpThumb->setCacheDirectory();
echo '<div style="background-color: ' . (is_dir($phpThumb->config_cache_directory) ? 'lime;">exists' : 'red;">does NOT exist') . '</div>';
echo '<div style="background-color: ' . (is_readable($phpThumb->config_cache_directory) ? 'lime;">readable' : 'red;">NOT readable') . '</div>';
echo '<div style="background-color: ' . (is_writable($phpThumb->config_cache_directory) ? 'lime;">writable' : 'red;">NOT writable') . '</div>';
echo '</th><td>Original: "' . htmlentities($orig_config_cache_directory) . '"<br>Resolved: "' . htmlentities($phpThumb->config_cache_directory) . '"<br>Must exist and be both readable and writable by PHP.</td></tr>';
echo '<tr><th>cache write test:</th><th colspan="2">';
$phpThumb->rawImageData = 'phpThumb.demo.check.php_cachetest';
$phpThumb->SetCacheFilename();
echo '<div>' . htmlentities($phpThumb->cache_filename ? implode(' / ', preg_split('#[/\\\\]#', $phpThumb->cache_filename)) : 'NO CACHE FILENAME RESOLVED') . '</div>';
echo '<div>directory ' . (is_dir(dirname($phpThumb->cache_filename)) ? 'exists' : 'does NOT exist') . ' (before EnsureDirectoryExists())</div>';
phpThumb_functions::EnsureDirectoryExists(dirname($phpThumb->cache_filename));
echo '<div style="background-color: ' . (is_dir(dirname($phpThumb->cache_filename)) ? 'lime;">directory exists' : 'red;">directory does NOT exist') . ' (after EnsureDirectoryExists())</div>';
if ($fp = @fopen($phpThumb->cache_filename, 'wb')) {
    fwrite($fp, 'this is a test from ' . __FILE__);
    fclose($fp);
    echo '<div style="background-color: lime;">write test succeeded</div>';
    $old_perms = substr(sprintf('%o', fileperms($phpThumb->cache_filename)), -4);
    @chmod($phpThumb->cache_filename, 0644);
    clearstatcache();
    $new_perms = substr(sprintf('%o', fileperms($phpThumb->cache_filename)), -4);
    echo '<div style="background-color: ' . ($new_perms == '0644' ? 'lime' : ($new_perms > '0644' ? 'orange' : 'red')) . ';">chmod($phpThumb->cache_filename, 0644) from "' . htmlentities($old_perms) . '" resulted in permissions "' . htmlentities($new_perms) . '"</div>';
    if (@unlink($phpThumb->cache_filename)) {
        echo '<div style="background-color: lime;">delete test succeeded</div>';
    } else {
        echo '<div style="background-color: red;">delete test FAILED</div>';
    }