Jump to content

stristr problem


keithvb

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/229385-stristr-problem/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/229385-stristr-problem/#findComment-1181901
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.