Friday, October 10, 2025
HomeLanguagesHow to create directory with HTML button and PHP ?

How to create directory with HTML button and PHP ?

The mkdir() function is used to create directory in PHP. It is an inbuilt function in PHP. The mkdir() function creates a new directory with the specified pathname. The path and mode are sent as parameters to the mkdir() function and it returns TRUE on success or FALSE on failure.

Syntax:

mkdir( path, mode, recursive, context )

Return Value: This function returns TRUE on success, or FALSE on failure.

Example:




<!DOCTYPE html>
<?php
    function createDirectory() {
        $add = $_POST["add"];
        mkdir("Gfg ".$add);
        echo "<script type = 'text/javascript'>alert('Done!');</script>";
    }
?>
<html>
    <head>
        <title>
            Create directory with HTML button and PHP 
        </title>
    </head>
      
    <body>
    <?php
        if (!isset($_POST['submit'])) {
    ?>
        <form action = "" method = "post">
              
            <table> 
            <tr>
                <td style = " border-style: none;"></td>
                <td bgcolor = "lightgreen" style = "font-weight: bold">
                    Enter Dummy Text and Then Press 'Create Directory'
                </td>
                  
                <td bgcolor = "lightred">
                    <input type = "text" style = "width: 220px;" 
                    class = "form-control" name = "add" id = "add" />
                </td>
                  
                <td bgcolor = "lightgreen" colspan = "2">
                    <input type = "submit" name = "submit" 
                        value = "Create directory" /> 
                </td>
            </tr>
            </table>
        </form>
    <?php 
        }
        else {
            createDirectory();
        }
    ?>
    </body>
</html>


Output:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32349 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6717 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7097 POSTS0 COMMENTS
Thapelo Manthata
6792 POSTS0 COMMENTS
Umr Jansen
6792 POSTS0 COMMENTS