0

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? :(

2
  • Check your logs. Also, mkdir returns a boolean, what is the return value? Commented Apr 18, 2017 at 20:56
  • 2
    <form method="POST"> Commented Apr 18, 2017 at 20:56

1 Answer 1

1

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';
}

?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.