I have a directory with images and I need to check a specific column of a table in my joomla database to see which files exist in the directory but not in the database and delete them.
What I've tried so far has not worked at all
my code is this
$dir = 'directory/of/files';
$files1 = scandir($dir);
$db =& JFactory::getDBO();
$query = "SELECT image FROM #__tablename WHERE something LIKE 'something else'";
$db->setQuery($query);
$result = $db->loadResultArray();
foreach ( $files1 as $file ) {
if (stripos($result, $file) === false) {echo 'file '.$file.' does not exist in database '; unlink($dir.$file);}
else {echo 'file '.$file.' exists in db ';}
}
Any ideas?
Thank you in advance