What is the significance of setting folder permissions to 0777 in PHP and how does it affect folder creation?

Setting folder permissions to 0777 in PHP allows full read, write, and execute permissions for all users on the system. This can be a security risk as it gives unrestricted access to the folder, making it vulnerable to malicious attacks. It is recommended to set more restrictive permissions based on the specific requirements of the application.

// Create a new folder with restricted permissions
$folderPath = 'path/to/new/folder';
if (!file_exists($folderPath)) {
    mkdir($folderPath, 0755, true);
}