Dara Shel
Dara Shel

Reputation: 37

Creating a new folder in another folder using PHP with name from input

I am trying to create a new folder in another folder, using the name for it from the input.

<form>
   Album name <input type="text" name="album_name">
    <input type="submit">
</form>

<?php

if(isset($_POST['album_name'])) {
    $albumName = $_POST['album_name'];
    $path = 'albums/' . $albumName;


    if (!file_exists($albumName)) {
        mkdir($path, 0777, true);
    }
}else{
    echo 'it is so saad';
}

?>

But the folder hasn't created. What is the problem? :(

Upvotes: 0

Views: 60

Answers (1)

Peter
Peter

Reputation: 741

Your script checks $_POST variable but you send data with GET method. Add method="POST" to your form tag, it will work.

<form method="POST">
   Album name <input type="text" name="album_name">
    <input type="submit">
</form>

<?php

if(isset($_POST['album_name'])) {
    $albumName = $_POST['album_name'];
    $path = 'albums/' . $albumName;


    if (!file_exists($albumName)) {
        mkdir($path, 0777, true);
    }
}else{
    echo 'it is so saad';
}

?>

Upvotes: 1

Related Questions