Then you either use the method of getting the information of last 5 entries, put those directories in an array, and then delete all files from the root directory you need to work with UNLESS they are in the array of recent 5. (Basically, use the code from inside the function on its own, modify it to check against that array using
in_array() and then also remove the line to remove the directory (which would be the root)
If you have other things in the root, well then you will need to read all the entries...
Code: Select all
$intLimiter = FALSE;
$rsRecords = mysql_query('SELECT `id`,`path` FROM `site` ORDER BY `id` DESC LIMIT 5');
if ($rsRecords && mysql_num_rows($rsRecords)>0) {
while ($aryTemp = mysql_fetch_assoc($rsRecords)) {
if ($intLimiter===FALSE) {
// This is the "5th oldest, so store it for the delete statement
$intLimiter = $aryTemp['id'];
}
else {
// We already processed row #5, so this is older delete it...
rrmdir($aryTemp['path']);
}
}
mysql_free_result($rsRecords);
}
mysql_query('DELETE FROM `site` WHERE `id` < '.$intLimiter);