Home » Programming » php » PHP Working with Directories

PHP Working with Directories

Handle a directory there are several functions in PHP language.
i. mkdir()
ii. opendir()
iii. readdir()
iv. scandir()
v. rmdir()
vi. closedir()

i. Create Directory
Want to create a new folder using PHP then use mkdir(). Only one argument is required the folder name or folder location where want to create the folder.

Example

ii. Open Directory
Using opendir() function can open a folder.Only one argument is required the folder path that is to be opened.

Example

iii. Read Directory
readdir() is used to read any folder content. Return the all files and sub directory list of the specified folder (what want to read). One argument is required the folder path.
Example

Output

iv.Scan Directory
sacndir() is same as readdir() but there are small difference. sacndir() return the all files and sub folder name as an array. One argument is required the folder path. No need to open folder in this case.

Example

”;
?>

Output

v. Remove Directory
rmdir() function is used to remove or delete any empty folder from the specified location. If the folder is not empty then rmdir() is not work.

Example

vi. Close Directory
closedir() function is used to closed any directory.

Example

Please follow and like us:
error