The dir() function in PHP used to find the instance of a Directory class. This function read directory, which includes the following:
- The given directory is opened.
- The two properties handle and path of dir() are available.
- The handle property can be used with other directory functions such as readdir(), rewinddir(), closedir(). The path property is set to path the directory that was opened
- Both handle and path properties have three methods: read(), rewind(), and close().
dir(string $directory, resource $context)
Parameters Used :
The dir() function accepts two parameters. They are illustrated as follows:
- $directory : It is a required parameter. It specifies the directory to be opened.
- $context : It is an optional parameter. It contains references to all modules in the
directory that can be required with a request matching the regular expression.
Return Value :
The above function will return an instance of the Directory class on success. Otherwise will return FALSE on Failure.
- The order in which directory entries are returned by the read method is system-dependent.
- This function defines the internal class Directory, meaning that we will not be able to define our own classes with that name.
Below is the implementation of above explained function :
Handle: Resource id #3 Path: /storage/ssd2/630/2687630/public_html filename: . filename: .. filename: bookkart filename: index.php filename: upload.html filename: hello.html filename: file-upload-manager.php filename: tmp.php filename: raj.php filename: gfgchecking filename: gfg.txt
Reference : http://php.net/manual/en/function.dir.php
- Copy the entire contents of a directory to another directory in PHP
- Comparison between static and instance method in PHP
- AWS EC2 Instance Setup with Apache Server
- How to Zip a directory in PHP?
- How to include() all PHP files from a directory ?
- How to count files in a directory using PHP?
- How to create directory with HTML button and PHP ?
- How to recursively delete a directory and its entire contents (files + sub dirs) in PHP?
- 10 Node.js Framework to be used in 2019
- Difference between VueJS and AngularJS
- How to check if a scrollbar is visible?
- How to change an element color based on value of the color picker value using onclick?
- Git-Checkout And Merge
- SASS | Comments
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.