bone282 commented on a Page, Random Image   -  Mar 27, 2010

i added the $fileType array

function dir2array($targetDir, &$fileType){
   $filesArray = array();
   if ($handle = opendir($targetDir)){
      while (false !== ($file = readdir($handle))){
         if(in_array(end(explode(".", $file)), $fileType)){
            $filesArray[] = $file;
            }
         }
         closedir($handle);
      }
   if (count($filesArray) > 0) {
      return $filesArray;
   } else {
      return FALSE;
      }
   }

// Usage Examples:

$arrayName = dir2array("path/to/directory", $arr = array("jpg", "png", "gif")); 
$randfile = $arrayName[array_rand($arrayName)];

if(FALSE !== ($arrayName = dir2array("path/to/directory", $arr = array("jpg", "png", "gif")))){ $randfile = $arrayName[array_rand($arrayName)]; }
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.