How can setting directory permissions in PHP impact the ability to manage files and folders on a server?

Setting directory permissions in PHP can impact the ability to manage files and folders on a server by restricting or allowing access to specific users or groups. It is important to set appropriate permissions to ensure that only authorized users can read, write, or execute files within a directory.

// Set directory permissions to allow read, write, and execute for owner, read and execute for group, and read-only for others
$directory = '/path/to/directory';
$permissions = 0755;

if (!file_exists($directory)) {
    mkdir($directory, $permissions, true);
} else {
    chmod($directory, $permissions);
}