PHP mkdir() Function
In this chapter you will learn:
- Definition for PHP mkdir() Function
- Syntax for PHP mkdir() Function
- Parameter for PHP mkdir() Function
- Return for PHP mkdir() Function
- Example - The mkdir() function creates a directory.
Definition
The mkdir() function creates a new directory .
Syntax
PHP mkdir() Function has the following syntax.
mkdir(path,mode,recursive,context)
Parameter
Parameter | Is Required | Description |
---|---|---|
path | Required. | Name of the directory to create |
mode | Optional. | Permissions. By default, the mode is 0777 (widest possible access). |
recursive | Optional. | If the recursive mode is set |
context | Optional. | Context of the file handle. Context is a set of options that can modify the behavior of a stream |
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
Return
Returns TRUE on success or FALSE on failure.
Example
The function returns true if the directory was created successfully or false otherwise. For example:
<?PHP//from jav a2s. c o m
mkdir("testing");
mkdir("/path/to/my/directory", 0777);
mkdir("/path/to/my/directory", 0777, true);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP move_uploaded_file() Function
- Syntax for PHP move_uploaded_file() Function
- Parameter for PHP move_uploaded_file() Function
- Return for PHP move_uploaded_file() Function
- Note on PHP move_uploaded_file() Function
- Example - moves an uploaded file to a new location
Home » PHP Tutorial » PHP File Functions