What are some common pitfalls when using PHP for file uploads, as seen in the provided code snippet?

One common pitfall when using PHP for file uploads is not checking the file type before allowing the upload, which can result in security vulnerabilities. To solve this issue, it is important to validate the file type before proceeding with the upload process.

// Check file type before allowing upload
$allowedFileTypes = ['jpg', 'jpeg', 'png', 'gif'];
$uploadedFileType = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));

if (!in_array($uploadedFileType, $allowedFileTypes)) {
    die("Invalid file type. Only JPG, JPEG, PNG, and GIF files are allowed.");
}

// Proceed with file upload
// Your file upload code here