To unzip a file with PHP, we can use the ZipArchive class. ZipArchive is a simple utility class for zipping and unzipping files. We don’t require any extra additional plugins for working with zip files. ZipArchive class provides us a facility to create a zip file or to extract the existing zip file. The ZipArchive class has a method called extractTo to extract the contents of the complete archive or the given files to the specified destination. The ZipArchive class also has a lot of other methods and properties to help you get more information about the archive before extracting all its contents.
bool ZipArchive::extractTo( string $destination, mixed $entries )
- destination: The $destination parameter can be used to specify the location where to extract the files.
- entries: The $entries parameter can be used to specify a single file name which is to be extracted, or you can use it to pass an array of files.
Example 1: This example unzip all the files from specific folder.
Description: Create an object of the ZipArchive class and open a given zip file using $zip->open() method.
If it returns TRUE then extract the file to the specified path with extractTo() method by passing path address as an argument in it.
Example 2: This example unzip the specific file from the folder.
Description: With the file element, you can select the zip file that you want to extract. If a selected file is valid then pass to open() method and extract it to the specified path using extractTo() method.
- Underscore.js | _.unzip() with Examples
- Node.js | zlib.unzip() Method
- Lodash _.unzip() Method
- How to get file input by selected file name without path using jQuery ?
- How to reset selected file with input tag file type in Angular 9?
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- How to move a file into a different folder on the server using PHP?
- Download file from URL using PHP
- How to delete a file using PHP ?
- How to copy a file from one directory to another using PHP ?
- How to make PDF file downloadable in HTML link using PHP ?
- How to delete text from file using preg_replace() function in PHP ?
- How to generate an XML file dynamically using PHP?
- How to append data in JSON file through HTML form using PHP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.