Directory functions in PHP

By | May 17, 2014

chdir-Change directory
chroot-change the root directory
closedir- Close directory handle
dir-Return an instance of the directory class
getcwd-gets the current working directory
opendir-open directory handle
readdir-read entry from the directory handle.
rewinddir-Rewind directory handle
scandir-list files and directories inside the specified path.

chdir and getcwd:

See the below example

Above example will output like below

/home/vasanthan
/home/vasanthan/mydoubts

chroot-change the root directory. it will change the current directory to ‘/’

Example:

Ouput as below

/

Opendir-Open a directory handle

it returns directory handle resource on success ,or false on failure

Examples

scandir-list files and directories inside the specified path.

Examples:

ouput will be like below

Array (
[0] => .
[1] => ..
[2] => index.php
)

tag:directory function in php,scandir example in php,opendir,chroot,getcwd

2. Sample script for reading csv file?

print_r($csvcontent);