What are recommended folder permissions for file uploads in PHP to ensure proper functionality?

When allowing file uploads in PHP, it is important to set the correct folder permissions to ensure proper functionality and security. The recommended folder permissions for file uploads in PHP are typically 755 for folders and 644 for files. This allows the web server to write to the upload folder while preventing unauthorized access to the uploaded files.

// Set folder permissions for file uploads
$uploadFolder = '/path/to/upload/folder';
chmod($uploadFolder, 0755);

// Set file permissions for uploaded files
$uploadedFile = '/path/to/uploaded/file.jpg';
chmod($uploadedFile, 0644);