Реализовал след. образом:
PHP:
// mysql files array
$file_bd_items = array();
$bd_files_name = mysqli_query($connect, "SELECT * FROM files");
while($row = mysqli_fetch_array($bd_files_name)) {
$file_bd_items[] = $row['filename'];
}
// server files array
$file_server_items = array();
foreach (scandir(ATTACHMENT_DIRECTORY) as $filename) {
$filepath = ATTACHMENT_DIRECTORY.$filename;
if (!is_file($filepath)) {
continue;
}
$file_server_items[] = $filename;
}
$result = array_values(array_diff($file_bd_items, $file_server_items));
$result_lenght = count($result);
for ($i = 0; $i < $result_lenght; $i++) {
$result_string_filename = $result[$i];
$bd_files_name = mysqli_query($connect, "DELETE FROM files WHERE filename in ('".$result_string_filename."');");
}
Cron:
find ~/sitename.ru/public_html/mailfile -type f -mtime +15 -print0 | xargs -0 rm -f