What are common pitfalls when using PHP for file uploads on a web server?

Common pitfalls when using PHP for file uploads on a web server include not properly validating file types, not checking for file size limits, and not securing the upload directory. To solve these issues, always validate file types using the `$_FILES['file']['type']` property, check file size limits using the `$_FILES['file']['size']` property, and ensure the upload directory has proper permissions set.

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

// Check file size limit
$maxFileSize = 2 * 1024 * 1024; // 2MB
if ($_FILES['file']['size'] > $maxFileSize) {
    die('File size exceeds limit. Maximum file size is 2MB.');
}

// Secure upload directory
$uploadDir = 'uploads/';
if (!is_dir($uploadDir)) {
    mkdir($uploadDir, 0755, true);
}

// Move uploaded file to upload directory
move_uploaded_file($_FILES['file']['tmp_name'], $uploadDir . $_FILES['file']['name']);
echo 'File uploaded successfully.';