Search code examples
phpapachemkdir

Php mkdir on apache server


I have to create a directory in apache server but it looks like if doesn't recognize the coomand. this is my code.

<?php



mkdir("var/www/devData/",0777);
print "created";

?>

when i launch the file.php i have as output "created" but after i use the shell for check if the dir is present but there is no dir. Anyone can help me?


Solution

  • error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    // a new directory in your current working directory (cwd)
    $path = dirname(__FILE__) . "/your/path";
    
    if(!mkdir($path, 0777, true)) {
        echo "Failure";
    } else {
        echo "Success";
    }
    

    I assume you do not have the permissions to create that path. You may check if you are able to write to that directory with is_writable() The mkdir() documentation tells you more.