What are some 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 accessible by the web server and not publicly accessible. This can help prevent unauthorized users from uploading malicious files or accessing sensitive information. One best practice is to set the directory permissions to 755, which allows the web server to read, write, and execute files within the directory, while restricting access to others.

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