Search code snippets, questions, articles...

Check if a folder already created using PHP

You can use this code to check whether a folder or directory already exists or not. We are using a PHP script to check that.
    $newdirname = $_POST["new_dir_name"];
    $dir_path = "path/to/" . $newdirname . "/";

    if (!file_exists($dir_path)) {
        mkdir($dir_path, 0777);
        echo "The directory creted successfully.";
    } else {
        echo "The directory already exists.";
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place.
Was this helpful?