I need to put together a quick script that will clean up a directory full of pictures for me. I want it to just delete photos that are not actively being used by members. I'm familiar with the different aspects involved in doing this but a little unsure of how to put it all together.
A simple query to select pics currently in use:
$sql=mysql_query("SELECT pic FROM user_profile_pics WHERE pic !=''");
while($r=mysql_fetch_array($sql)){
$pic=$r['pic']; }
Listing the contents of the dir.
$dirname = "some_dir";
$dir = opendir($dirname);
while(false != ($file = readdir($dir)))
{
if(($file != ".") and ($file != "..") ) // Edit
{
echo("$file <br />");
}
}
And of course I've used unlink()
to give files the axe.
The problem is that I tested a few things out with unexpected results and I really need to get it right before I set it loose on an active members db.