What potential pitfalls should be avoided when working with photo uploads in PHP?

One potential pitfall when working with photo uploads in PHP is not properly validating the file type before allowing it to be uploaded. This can lead to security vulnerabilities such as allowing malicious files to be uploaded to the server. To avoid this, always validate the file type before processing the upload.

// Validate file type before uploading
$allowedFileTypes = ['image/jpeg', 'image/png', 'image/gif'];
if (!in_array($_FILES['file']['type'], $allowedFileTypes)) {
    echo 'Invalid file type. Only JPEG, PNG, and GIF files are allowed.';
    exit;
}

// Process the file upload
// Add your code to move the file to the desired location