I have a big images folder with more than 100 000 images. (profile image)
I want to delete every image that is not store in the db (table userimages)
I think that i should scan every file, then get the name of the current file and then, check in my UserImages table if this filename exists... if not...i delete the image.
I found this code, this code is to delete file older than 7 days.. but i will fix it to my needs
$days = 7;
$path = './logs/';
$filetypes_to_delete = array("pdf");
// Open the directory
if ($handle = opendir($path))
{
// Loop through the directory
while (false !== ($file = readdir($handle)))
{
if (is_file($path.$file))
{
$file_info = pathinfo($path.$file)
//check if exist in db
//if not exist.... i delete the file
}
}
}
That way, is it good for a folder with a lot of images ? More than 100 000 ?
also i will do 100 000 query to the database.... is it good ?
Is there a better way to do that ?
Thanks a lot !
Pascal