Q. Write a php code to unzip `.zip` file
Solution:
<?php
// Specify the path to the zip file
$zipFilePath = 'path/to/sample.zip';
// Specify the directory where you want to extract the contents
$extractPath = 'path/to/output/folder/';
// Create a ZipArchive object
$zip = new ZipArchive;
// Open the zip file
if ($zip->open($zipFilePath) === TRUE) {
// Extract the contents to the specified directory
$zip->extractTo($extractPath);
// Close the zip file
$zip->close();
echo 'Extraction successful!';
} else {
echo 'Failed to open the zip file';
}
?>
No comments:
Post a Comment