What are the potential pitfalls of using global variables in PHP when uploading files?

Using global variables in PHP when uploading files can lead to security vulnerabilities such as data injection attacks or unintended data manipulation. To avoid these pitfalls, it is recommended to use superglobal arrays like $_FILES to handle file uploads securely.

// Example of securely handling file uploads without using global variables
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $file = $_FILES['file'];
    
    // Handle file upload securely
}