[eluser]JoostV[/eluser]
If you use a key=>value pair array for the files from the DB, you can loop through all files and check if they are in that array
Code:
if(!in_array($file, $file_array)) {
// Unlink the file
}
You array would have to be like
Code:
$file_array = array('file1.jpg', 'file2.jpg');
When you loop through the folder contents, be careful to unlink only files, not folders or empty values