It’s Festive Season! Enjoy 30% Off

Use code FESTIVE30 at checkout

Code has been added to clipboard!

The Complete Guide on PHP Directory: Master Functions

Reading time 2 min
Published Aug 8, 2017
Updated Oct 2, 2019

A PHP directory is a structure used to catalog and keep our files. It's a part of an organizing system that lets us keep track of our projects and code files more easily.

PHP has a bunch of inbuilt functions that let us quickly fetch information about particular PHP files in the directory. Additionally, it is possible to retrieve data about a whole specific PHP directory. We can easily make PHP list files in directory, open specified handles, and perform other tasks.

PHP Directory: Main Tips

  • Directory functions allow you to get info about various PHP directories and what they contain.
  • These functions are inbuilt into the PHP's core.
Theory is great, but we recommend digging deeper!

List of Useful Functions

The following list contains the functions you can apply in order to manipulate every PHP directory you create:

Function Description
chdir() Change current PHP directory
chroot() Change root directory
closedir() Close directory handle
dir() Return instance of directory class
dirname() Make PHP get root directory
getcwd() Return current working PHP directory
opendir() Open specified directory handle
readdir() Return entry from directory handle
rewinddir() Reset directory handle
scandir() Make PHP list files in directoryReturn array of PHP files in directory specified (or directories from multidimensional array)

PHP Directory: Summary

  • Information on any PHP file directory and the files it contains can be obtained using PHP directory functions.
  • These functions are inbuilt, and therefore don't require installation.