Home » PHP

PHP mkdir() function with example

PHP mkdir() function: Here, we are going to learn about the PHP mkdir() function with its syntax, parameters, returns type, and example.
Submitted by IncludeHelp, on August 11, 2019

PHP mkdir() function

The full form of mkdir is "Make Directory", the function mkdir() is used to create a directory.

Syntax:

    mkdir(dir_path, access_mode, recursive, context);

Parameter(s):

  • dir_path – It defines the path to the directory, where we want to create a directory.
  • access_mode – It is an optional parameter; its default value is 0777 that stands for the widest possible access. There are 4 values to be set for the access mode,
    • The first value should be 0
    • The second value sets the permission for the owner
    • The third value sets the permission for the owner's user group
    • The fourth value sets the permission for everybody else
      The values are 1 for execute permission, 2 for write permission, 4 for reading permission, we can add values to set the specific permissions, for example, 1+2+4 = 7 = permission for executing, write and read.
    Note: The access_mode parameter is ignored on Windows system.
  • recursive – It is also an optional parameter; It defines the recursive mode.
  • context -  It is also an optional parameter; It sets the context (a set of options that can modify the behavior of a stream) of the file handling.

Return value:

It returns a Boolean value, "TRUE" – if the directory creates successfully or "FALSE" – if the directory does not create.

Example: PHP code to create directory

<?php

//creating the directory
$ret_value = mkdir("/home/folder1");

if ($ret_value == true)
    echo "directory created successfully...";
else
    echo "directory is not created successfully...";

?>

Output

directory created successfully...

Reference: PHP mkdir() function







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.