How to Create Directory Using PHP

How to create directory using php - The directory or folder is a storage location on the hard drive containing files or other directories. In a directory can contain many files and many other directories called subdirectories. PHP provides several functions to handle directories such as creating directories, removing directories, reading directory contents, opening directories and closing directories. But in this post I just discuss about tutorial how to create a new directory using php, for others I may be discussed in other posts.
Program
File Name: file08.php
Description: The program creates a new directory.
Type the following php code into notepad.
<?php
$dir = "images"; //Directory name
$cek = mkdir ($dir);
if ($cek) {
 echo "Direktori <b>$dir</b> Successfully created";  
 } else {  
 echo "Direktori <b>$dir</b> Failed to create";  
 }
?>

How to Create Directory Using php

Save the code with file08.php name in htdocs folder.
Program Explanation
The above program will create a directory named "images" in the directory where the program is stored. The function to create a new directory in PHP is mkdir(). If the directory to be created is outside where the program is stored, then include the full directory path.
To run the program create a new directory, open the browser then type http://localhost/file08.php on the address bar then enter. If successful then it will display the message "Directory images Successfully created".
How to Create Directory Using php
Program view

Try now look at the directory, open explorre C:\xampplite\htdocs then there will be directory or folder images.
How to Create Directory Using php
Directory successfully created

That's the tutorial from me, about how to create directory using php. Hope can increase our knowledge about php programming language. Learn also tutorial about: Closing File in PHP.

Comments