What are the best practices for setting permissions on temporary directories for file uploads in PHP?

When setting permissions on temporary directories for file uploads in PHP, it is important to ensure that the directory is writable by the web server, but not accessible for execution. This can be achieved by setting the permissions to 755, which allows the owner to read, write, and execute, while others can only read and execute.

// Set permissions on temporary directory for file uploads
$dir = '/path/to/temporary/directory';
chmod($dir, 0755);