js

Thursday, February 29, 2024

PHP: write a php code to unzip `.zip` file

 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

SEBA HSLC Question Paper Science 2023