I have a function that downloads all image files found in the wordpress download directory. I would like to modify it a bit so that it skips any image starting with an underscore, "_someimage.jpg" is skipped, and "someimage.jpg is not ...
Here is the existing function ....
$dir = 'wp-content/uploads/';
$url = get_bloginfo('url').'/wp-content/uploads/';
$imgs = array();
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if (!is_dir($file) && preg_match("/\.(bmp|jpeg|gif|png|jpg|)$/i", $file))
{
array_push($imgs, $file);
}
}
closedir($dh);
} else {
die('cannot open ' . $dir);
}
source
share