if (!file_exists('mydir')) { mkdir('mydir'); echo 'Directory "mydir" created successfully!'; } else { echo 'Directory "mydir" already exists!'; }
$path = '/var/www/html/uploads/'; if (!file_exists($path)) { mkdir($path, 0777, true); echo 'Directory "' . $path . '" created successfully!'; } else { echo 'Directory "' . $path . '" already exists!'; }In Example 2, we are creating a directory named "uploads" in the "/var/www/html/" directory. The third parameter to `mkdir()` is set to `true`, which means that any missing directories in the path will be created automatically. The package library for `mkdir()` is part of the PHP core, so no additional libraries are needed to use it.