PHP/File Directory/glob

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

glob() Constants

   <source lang="html4strict">

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.

 </source>
   
  


Using glob()

   <source lang="html4strict">

<?php foreach (glob("/usr/local/docs/*.txt") as $file) {

  $contents = file_get_contents($file);
  print "$file contains $contents\n";

} ?>

 </source>
   
  


Using the glob() Function

   <source lang="html4strict">

<?php

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

?>

 </source>