if (!file_exists('new_directory')) { mkdir('new_directory', 0777, true); echo 'New directory created successfully.'; } else { echo 'Directory already exists.'; }
if (!file_exists('/path/to/new_directory')) { mkdir('/path/to/new_directory', 0700, true); echo 'New directory created successfully.'; } else { echo 'Directory already exists.'; }This code creates a new directory "/path/to/new_directory" with read, write, and execute permissions for the owner only. It also creates all parent directories if they do not exist. The makeDirectory function is part of the PHP Filesystem extension, which is included in the standard PHP library.