Jump to: navigation, search

Php opendir

From w3cyberlearnings

Contents

PHP function opendir

This function opens a directory handle.

Syntax opendir

  • dir is a directory
  • context is a description of the directory handle.
opendir(dir,context);

Note

It is also support ftp:// URL wrapper.

Example 1

<?php 

$dh = opendir(dirname(__FILE__) . '/mydir');


?>

Example 2

<?php 
  $path = dirname(__FILE__).'/mydir';
  $dh = opendir($path);
  while(($d = readdir($dh)) !== false) {
     $pfile = $path. '/'. $d;
     echo $pfile ."\n";
    // echo "name: $d : type: ". filetype($pfile)."\n";
  }
  closedir($dh);
?>

Output

/home/w3cyberlearnings/testphp/mydir/learn.txt
/home/w3cyberlearnings/testphp/mydir/a1
/home/w3cyberlearnings/testphp/mydir/ac
/home/w3cyberlearnings/testphp/mydir/a2
/home/w3cyberlearnings/testphp/mydir/.
/home/w3cyberlearnings/testphp/mydir/ab
/home/w3cyberlearnings/testphp/mydir/..


--chdir-- chroot-- closedir-- dir-- getcwd-- opendir-- readdir-- rewinddir-- scandir--

Navigation
Web
SQL
MISC
References