PHP creating & deleting directories Creating directories:
PHP’s mkdir() can be used to create directories. It takes two parameters; path to desired directory and the permission.
Mkdir(*/temp/sample*, 0777);Deleting directories:
PHP’s rmdir() can be used to delete directories. It takes one parameter as the directory name to be deleted.
Explain the working with directories using opendir(), readdirs(), closedir() along with examples.Opendir():-
It opens the directory. This function returns a directory stream on success and FALSE and an error on failure.Syntax:
Context is a set of options that can modify the behavior of a streamExample:
opens sample directory.
$dir = opendir("directory");Readdir():
It returns an entry from a directory handle opened by opendir().Syntax:
$file = readdir($dir);closedir():
It closes a directory handle opened by opendir().Syntax:
$file = close($dir);
Write short note on creating directories, mkdir function with an example.Mkdir():
creates a directory.Syntax:
Mode: Optional. Specifies permissions. By default, the mode is 0777 (widest possible access).
The mode parameter consists of four numbers:
- The first number is always zero
- The second number specifies permissions for the owner
- The third number specifies permissions for the owner's user group
- The fourth number specifies permissions for everybody else
Possible values (to set multiple permissions, add up the following numbers):
- 1 = execute permissions
- 2 = write permissions
- 4 = read permissions
Recursive – optional and specifies if recursive
Context – optional and Specifies the context of the file handle.Example:
Write short note on deleting directories, rmdir() with an example.
Rmdir() removes the directory which is empty.Syntax:
optional. Context is a set of options that can modify the behavior of a streamExample:
$var = "images";
echo ("Could not remove $var");