How to enable zip extension in xampp

How to Enable the ZIP Extension in XAMPP?

To enable the ZIP extension in XAMPP, you need to follow these steps:

  1. Locate the “php.ini” file in your XAMPP installation directory.
  2. Open the “php.ini” file in a text editor.
  3. Search for the following line:
    ;extension=zip
  4. Remove the semicolon (;) at the beginning of the line to uncomment it.
  5. Save the changes and close the “php.ini” file.
  6. Restart the Apache web server from the XAMPP control panel.

Once you have completed these steps, the ZIP extension should be enabled in XAMPP. You can test it by running a script that uses ZIP functions and see if it executes without any errors.

Here’s an example of a simple PHP script that uses the ZIP extension to create a ZIP archive:

<?php
$zip = new ZipArchive();
$filename = "./example.zip";

if ($zip->open($filename, ZipArchive::CREATE) !== true) {
    exit("Cannot open $filename");
}

$zip->addFromString("example.txt", "This is a text file.");

$zip->close();

echo "ZIP archive created successfully!";
?>

Save this script in your XAMPP web server’s document root directory and access it through a web browser. If the ZIP extension is correctly enabled, it should create a file named “example.zip” containing a text file when executed.

Leave a comment