In this tutorial I will present PHP functions that are used to work with directories: chdir, getcwd, chroot, rewinddir, opendir, closedir, readdir, mkdir, rmdir.
- chdir is used to change the current directory. It takes one parameter which is the new directory and returns TRUE or FALSE depending on our request: successful or not.
- getcwd gives the curent directory.
- chroot is used to change the root directory for the the current process and receives a set of characters, returning TRUE or FALSE. This function is not implemented on Microsoft Windows platforms, and is recommended to be used only if PHP interpreter is used with CGI execution method.
- opendir is used for opening a directory for reading the files in it. It returns an access identifier of resource type if the call of opendir is successful, or FALSE otherwise.
- closedir is used for closing an open directory. Is a void function which means that is not returning anything. We must pass as a parameter the resource obtained on open the directory using opendir.
- rewinddir – resets the current position within a directory. For example, if after a number of reads this function is called, and we read another entry from that directory, the first entry is returned.
- mkdir – receives a string as a parameter together with it’s attributes (unix formats as integers) and returns TRUE or FALSE.
- rmdir – receives a string as a parameter and removes that directory. That directory must be empty: no subfolders or files in it. Returns true or false.
Thanks for reading this tutorial.
Leave a Reply