keithvb Posted March 2, 2011 Share Posted March 2, 2011 Is there a better way to specify the "if (strsistr...)" line? Suppose I want to check 4 or 5 file ext's instead of just 2? <?php if ($handle = opendir('pics')) { echo 'Directory handle: ' . $handle . '<br />'; echo 'Files: <br />'; while (false !== ($file = readdir($handle))) { if ( stristr($file,("jpg")) || stristr($file,("png")) ) { echo $file . '<br />'; } } closedir($handle); } ?> thanks, Keith Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 2, 2011 Share Posted March 2, 2011 Why don't you use the glob() function and just get the files with the extensions you want? <?php $files = glob('pics/*.{jpg,png,gif}',GLOB_BRACE); echo "Files: <br />\n": foreach ($files as $file) { echo basename($file) . "<br />\n": } ?> Ken Quote Link to comment Share on other sites More sharing options...
keithvb Posted March 2, 2011 Author Share Posted March 2, 2011 Thanks, Ken. That works. Didn't know about glob Now to integrate it into the slide show I'm attempting... Keith Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.