What are the potential pitfalls of not having proper permissions set for the upload directory in PHP?

If proper permissions are not set for the upload directory in PHP, it can lead to security vulnerabilities such as allowing unauthorized users to upload malicious files or overwrite existing files. To solve this issue, you should ensure that the upload directory has the correct permissions set to restrict access only to authorized users.

// Set proper permissions for the upload directory
$uploadDir = 'uploads/';

// Check if the directory exists, if not create it
if (!file_exists($uploadDir)) {
    mkdir($uploadDir, 0755, true);
}