How can one determine if a ZIP file is password protected in PHP?

To determine if a ZIP file is password protected in PHP, you can use the ZipArchive class to open the ZIP file and check if it requires a password to extract its contents. If the ZIP file is password protected, the ZipArchive::open() method will return false.

$zip = new ZipArchive();
$zipFile = 'example.zip';

if ($zip->open($zipFile) === true) {
    echo 'ZIP file is not password protected.';
    $zip->close();
} else {
    echo 'ZIP file is password protected.';
}