Hey,

I need some help, I need my script to loop through a directory of images and only delete images that contain "t.jpg"...

Here is my looping script...

<?php
// First we need to loop through the files....
$image_dir = $_GET['dir'];

if(!opendir($image_dir)){
	echo error_msg("Ooops... This Album contains no images");
	
}else{
		

if ($handle = opendir($image_dir)) {
while (false !== ($file = readdir($handle))) 
{
if ($file != '.' && $file != '..' &&$file != '_notes' && $file != 'master.jpg' && $file != '.DS_Store') 
{
$files[] = $file;
}
}
closedir($handle);
}

sort($files);

foreach($files as $file){
	
	// Unlink only images that contain t.jpg....
	
}

echo "<script type='text/javascript'>alert('Done!');</script>";

}
?>

Dan

Hi Dan,

You can do something like this:

foreach($files as $file){
// Unlink only images that contain t.jpg....
    $find = "t.jpg";
    $pos = strpos($file, $find);
    if ($pos !== false) {
        unlink($file);
    }
}

Hope it helps!

Adnan