Skip to content
PHP Logo

How can PHP be used to create a directory in a specific location outside of the current directory?

To create a directory in a specific location outside of the current directory using PHP, you can use the `mkdir()` function with the full path of the directory you want to create. Make sure you have the necessary permissions to create directories in the specified location.

php
$directoryPath = '/path/to/new/directory';
if (!file_exists($directoryPath)) {
    mkdir($directoryPath, 0777, true);
    echo "Directory created successfully.";
} else {
    echo "Directory already exists.";
}