From c13c7a1d25fd356c6139ef200593a00ca1c1d349 Mon Sep 17 00:00:00 2001 From: Mitsukarenai Date: Thu, 3 Dec 2015 22:09:18 +0100 Subject: [PATCH] cache: check if cache folder exists --- index.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/index.php b/index.php index 03ae2ef..75eadda 100644 --- a/index.php +++ b/index.php @@ -26,17 +26,19 @@ ini_set('user_agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20121202 F // cache file purge - delete cache files older than 24 hours $cacheTimeLimit = time() - 60*60*24 ; $cachePath = 'cache'; -$cacheIterator = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($cachePath), - RecursiveIteratorIterator::CHILD_FIRST -); -foreach ($cacheIterator as $cacheFile) { - if (in_array($cacheFile->getBasename(), array('.', '..'))) - continue; - elseif ($cacheFile->isFile()) { - if( filemtime($cacheFile->getPathname()) < $cacheTimeLimit ) - unlink( $cacheFile->getPathname() ); - } +if(file_exists($cachePath)) { + $cacheIterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($cachePath), + RecursiveIteratorIterator::CHILD_FIRST + ); + foreach ($cacheIterator as $cacheFile) { + if (in_array($cacheFile->getBasename(), array('.', '..'))) + continue; + elseif ($cacheFile->isFile()) { + if( filemtime($cacheFile->getPathname()) < $cacheTimeLimit ) + unlink( $cacheFile->getPathname() ); + } + } } // default whitelist