Forum Moderators: coopster
function getFirstImage($dirname)
{
global $imageName;
$ext = array("jpg", "png", "jpeg", "gif", "JPG", "PNG", "GIF", "JPEG");
if($handle = opendir($dirname))
{
while(false!== ($file = readdir($handle)))
{
if(strstr($file, "." . $ext[$i]))
{
$imageName = $file;
break;
}
}
closedir($handle);
}
return($imageName);
}
just trying to get the name if the first image in the spacified folder...
thanks for any help!
as an aside instead of strstr you could use the case insensitive version so you don't have to have both upper and lower case extensions in your comparison array and it would then handle mixed case extensions
[php.net...]
function getFirstImage($dirname)
{
global $imageName;
$ext = array("jpg", "png", "jpeg", "gif", "JPG", "PNG", "GIF", "JPEG");
if($handle = opendir($dirname))
{
while(false!== ($file = readdir($handle)))
{
if(strstr($file, "." . $ext[$i])!= '.' && strstr($file, "." . $ext[$i])!= '..')
{
break;
}
}
$imageName = $file;
closedir($handle);
}
return($imageName);
}
that way is solid cause then if returns '..' you know it has no images... will lookinto that stristr function
thanks,
jonathan