|  | Posted by Confused but working on it on 09/12/07 04:51 
On 2007-09-11 15:12:16 -0700, Michael Fesser <netizen@gmx.de> said:
 > .oO(Confused but working on it)
 >
 >> Now it appears I have files named "." and "..", well, back to the manual...
 >
 > readdir() returns _all_ directory entries, normal files and other
 > directories. You can use is_file() or is_dir() to filter out the
 > unwanted. See the manual for details and examples.
 >
 > Micha
 
 I got this from the manual:
 
 <?php
 var_dump(is_dir('a_file.txt')) . "\n";
 var_dump(is_dir('bogus_dir/abc')) . "\n";
 
 var_dump(is_dir('..')); //one dir up
 ?>
 The above example will output:
 bool(false)
 bool(false)
 bool(true)
 
 Don't think I need the var dump part. Below I inserted where I think
 the test should go. Basically read from the directory, test to see if
 it's a dir, if a dir get the next $file, if not echo. I don't think I
 can replace the readdir with the is_dir because the first two items ARE
 directories so I can't tell it to stop if it sees a dir.
 <?php
 //Open images directory
 $dir = opendir("images");
 //List files in images directory
 while (($file = readdir($dir)) !== false)
 {
 // Test for file or directory with is_dir like if $file is a directory
 get the next $file.
 echo "<img src='images/$file'>";
 }
 closedir($dir);
 ?>
 
 I didn't see any very simple examples of get me everything that is a
 ".jpg" type of thing which would work too.
 
 Time for some sleep. :)
  Navigation: [Reply to this message] |