PHP/File Directory/glob

Материал из Web эксперт
Перейти к: навигация, поиск

glob() Constants

 
GLOB_MARK       Append a slash to filenames that are really directories.
 
GLOB_NOSORT     Do not sort the returned filenames.
 
GLOB_NOCHECK    If no files were found that match the filemask, return the filemask instead of an empty array.
 
GLOB_ONLYDIR    Match only directories that meet the filemask.



Using glob()

 
<?php
foreach (glob("/usr/local/docs/*.txt") as $file) {
   $contents = file_get_contents($file);
   print "$file contains $contents\n";
}
?>



Using the glob() Function

 
<?php
     $directories = glob("/tmp/*", GLOB_ONLYDIR);
     $complete = glob("/tmp/*");
     $files = array_diff($directories, $complete);
     echo "Directories in /tmp/<BR>";
     foreach($directories as $val) {
          echo "$val<BR>\n";
     }
     echo "<BR>Files in /tmp/<BR>";
     foreach($files as $val) {
          echo "$val<BR>\n";
     }
?>