What are some best practices for securely uploading and handling zip files in PHP applications?

When handling zip files in PHP applications, it is crucial to ensure that proper security measures are in place to prevent any potential vulnerabilities such as zip bombs or malicious code execution. One best practice is to validate and sanitize the uploaded zip file before extracting its contents to prevent any security risks.

// Validate and sanitize the uploaded zip file
$zip_file = $_FILES['zip_file']['tmp_name'];
$zip = new ZipArchive;
if ($zip->open($zip_file) === TRUE) {
    // Extract the contents of the zip file
    $zip->extractTo('uploads/');
    $zip->close();
    echo 'Zip file uploaded and extracted successfully.';
} else {
    echo 'Failed to upload and extract zip file.';
}