What are common pitfalls when uploading files in PHP, especially when handling zip files?

When uploading zip files in PHP, a common pitfall is not checking the file type or size before processing it. This can lead to security vulnerabilities or server overload. To mitigate this, always validate the file type and size before handling the uploaded zip file.

// Validate file type and size before handling the uploaded zip file
$allowedTypes = ['application/zip'];
$maxFileSize = 10 * 1024 * 1024; // 10MB

if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
    $fileType = $_FILES['file']['type'];
    $fileSize = $_FILES['file']['size'];

    if (in_array($fileType, $allowedTypes) && $fileSize <= $maxFileSize) {
        // Process the uploaded zip file
    } else {
        echo 'Invalid file type or size. Please upload a zip file within 10MB.';
    }
} else {
    echo 'Error uploading file. Please try again.';
}