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.';
}
Related Questions
- What potential issue could arise from using register_globals set to 'on' in PHP?
- How can JavaScript be used to enhance the user experience in a PHP live chat application while still ensuring server-side reliability for user management?
- What potential issues can arise from not properly closing brackets in PHP code, as seen in the provided script?