How to Create a Folder/Directory using php

We can create a folder with the help of mkdir already defined function

We can use tis function like this

Description:

bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )

Parameter:


pathname:

The directory path.

mode:

The mode is used to define accessibility of the folder

recursive

Allows the creation of nested directories specified in the pathname. Defaults to FALSE.

Return Values:

Returns TRUE on success or FALSE on failure.

Example 1:

<?php
mkdir(“/path/to/my-dir”, 0777);
?>

Example 2:

<?php
// Desired folder structure
$dir = ‘/path/to/my-dir’;

// To create the nested structure, the $recursive parameter
// to mkdir() must be specified.

if (!mkdir($dir, 0, true)) {
die(‘Failed to create folders…’);
}
?>

Share This Post

Post Comment