Listing certain extensions in PHP Dir List -


have following provide dir list in array

for($index=0; $index < $indexcount; $index++) {         if (substr("$dirarray[$index]", 0, 1) != ".") { // don't list hidden files  echo "<option value=\"".$dirarray[$index]."\">".$dirarray[$index]."</option>";  } 

is there way can modify above code .jpg , .png displayed?

thanks!

cp

you can use regular expression match if file name ends .jpg or .png

for($index=0; $index < $indexcount; $index++)  {     if(preg_match("/^.*\.(jpg|png)$/i", $dirarray[$index]) == 1)      {       echo "<option value=\"".$dirarray[$index]."\">".$dirarray[$index]."</option>";     } } 

/i @ end of regular expression case insensitive flag.


Comments