What are the best practices for setting permissions on upload directories in PHP?

When setting permissions on upload directories in PHP, it is important to ensure that the directory is only writable by the web server and not accessible by other users. This helps prevent unauthorized users from uploading malicious files or accessing sensitive information. The recommended permissions for an upload directory are typically 755, which allows the web server to write to the directory but restricts access to others.

// Set permissions on upload directory
$uploadDir = '/path/to/upload/directory';
chmod($uploadDir, 0755);