• PHP Video Tutorials

PHP - Function mkdir()



The mkdir() function can create a directory, and this function can return true on success, or false on failure.

Syntax

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

This function can attempt to create a directory specified by pathname.

Example-1

<?php
   mkdir("/PhpProject/testing");
   echo "Directory created successfully!!!";
?>

Output

Directory created successfully!!!

Syntax

Example-2

<?php
   $structure = "/PhpProject/test1/test2/test3";

   if(!mkdir($structure, 0777, true)) {
      echo "Failed to create folders...";
   } else {	
       echo "Nested structure created successfully!!!";
   }
?>

Output

Nested structure created successfully!!!
php_function_reference.htm
Advertisements