我不确定是什么问题,因为我可以删除和修改同一目录级别的文件而没有任何问题。这是我正在运行的脚本,用于对所有目录进行排序并找到任何TimThumb缓存。
$caches = array();
function searchForThumbCaches($dir=false, &$results=false) {
if ( !is_array($results) )
$results = array();
if ( !$dir )
$dir = $_SERVER['DOCUMENT_ROOT'];
$thumbFileFound = false;
$cacheDirFound = false;
//echo 'Scanning dir `'.$dir.'`';
foreach(scandir($dir) as $item) {
$path = slash($dir.'/'.$item);
if ( $item == '.' || $item == '..' )
continue;
//echo 'Found item `'.$item.'` (`'.$path.'`)<br />';
if ( $item == 'cache' && is_dir($path) )
$cacheDirFound = true;
if ( $item == 'thumb.php' )
$thumbFileFound = true;
if ( is_dir($path) )
searchForThumbCaches($path, $results);
}
if ( $thumbFileFound && $cacheDirFound )
$results[] = slash($dir.'/cache');
return $results;
}
$thumbCaches = searchForThumbCaches();
foreach($thumbCaches as $cachePath) {
chmod($cachePath, 0777);
echo 'Cache `'.$cachePath.'`<br />';
foreach(scandir($cachePath) as $cacheFile) {
if ( $cacheFile == '.' || $cacheFile == '..' || $cacheFile == 'index.html' )
continue;
$path = slash($cachePath.'/'.$cacheFile);
unlink($path);
}
}
但是,chmod()
或unlink()
操作都不起作用,它们都会返回错误,例如此示例输出:
Cache `/var/www/example.com/web/engine/img/dashboard/cache`
Warning: chmod(): Operation not permitted in /var/www/example.com/web/thumb.cache.clear.php on line 46
Cache `/var/www/example.com/web/engine/ui/themes/default/img/dashboard/cache`
Warning: unlink(/var/www/example.com/web/engine/ui/themes/default/img/dashboard/cache/timthumb_cacheLastCleanTime.touch): Permission denied in /var/www/example.com/web/thumb.cache.clear.php on line 52
我试过在像CyberDuck这样的FTP客户端中删除它们,但我做的一切似乎都没有用。无论如何都要覆盖这些权限,或者我只是运气不好?