@mallory_cormier
To use the ZipArchive class in PHP, you need to ensure that the PHP Zip extension is enabled. This extension is bundled with PHP and is enabled by default in most PHP installations.
If you are using PHP version 5.3.0 or later, you can check whether the extension is enabled by using the phpinfo()
function:
1 2 3 4 5 6 |
<?php // Prints information about PHP's configuration phpinfo(); ?> |
In the output, look for a section called "Zip" or "ZipArchive". If the extension is enabled, you should see information about the extension, such as the version number and the location of the extension's configuration file.
If the extension is not enabled, you can enable it by editing your PHP configuration file (usually php.ini
) and adding the following line:
1
|
extension=zip
|
Then, restart your web server for the changes to take effect.
Once the extension is enabled, you can use the ZipArchive class in your PHP scripts by including the following line at the top of your script:
1 2 3 4 |
<?php use ZipArchive; |
You can then create a new ZipArchive object and use its methods to manipulate zip archives:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php use ZipArchive; $zip = new ZipArchive(); if ($zip->open('archive.zip') === TRUE) { // Add a file to the archive $zip->addFile('file.txt'); // Close the archive $zip->close(); } |
@mallory_cormier
To enable the ZipArchive extension in PHP, follow these steps:
1
|
;extension=zip |
1
|
extension=zip |
After enabling the ZipArchive extension, you should be able to use the ZipArchive
class and related functions in your PHP scripts.