PHP Directory Functions

These functions are provided to manipulate any directory.

Installation

There is no installation needed to use these functions; they are part of the PHP core. PHP needs to be configured with --enable-chroot-func option to enable chroot() function.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Directory Functions List

Function Description
chdir() This function is used to change the current directory
chroot() By using this function ,we can change the current process directory to the specified directory (or) This chroot() function changes the current process directory to the specified directory
closedir() This closedir() function closes the opened directory handle opened by opendir() function
dir() The dir() function opens a directory handle and returns an object. The object contains three methods called read() , rewind() , and close() . This function returns a directory stream on success and FALSE and an error on failure
getcwd() Returns the current working directory on success, or FALSE on failure
opendir() This function opens a directory handle to be used in subsequent closedir(), readdir(), and rewinddir() functions. This function returns a directory stream on success and FALSE and an error on failure.
readdir() It reads the files exists in directory. The filenames are returned in the order in which they are stored by the filesystem. This function returns a filename on success and FALSE on failure
rewinddir() The rewinddir() function resets the directory handle opened by opendir().This function returns nothing.
scandir() This function reads all files information of a directory and returns the output as an array. Returns an array of files and directories from the passed directory.

Directory Functions Constants List

Constants Description
PATH_SEPERATOR

Subscribe to our Newsletter

Join our newsletter and get news in your inbox every week! We hate spam too, so no worries about this.

mail