Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
How to Zip and Unzip Files in Windows 11?
Next article icon

How to unzip a file using PHP ?

Last Updated : 22 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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. Syntax:
  bool ZipArchive::extractTo( string $destination, mixed $entries )
Parameters:
  • 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. php
<?php  $zip = new ZipArchive;  // Zip File Name if ($zip->open('GeeksforGeeks.zip') === TRUE) {      // Unzip Path     $zip->extractTo('/Destination/Directory/');     $zip->close();     echo 'Unzipped Process Successful!'; } else {     echo 'Unzipped Process failed'; } ?> 
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. php
<?php  $zip = new ZipArchive;  // Zip File Name $res = $zip->open('GeeksForGeeks.zip');  if ($res === TRUE) {          // Unzip Path      $zip->extractTo('/Destination/Directory/',         array('H_W.gif', 'helloworld.php'));              $zip->close();     echo 'Unzipped Process Successful!'; } else {     echo 'Unzipped Process failed'; } 
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.

Next Article
How to Zip and Unzip Files in Windows 11?

J

joshikashyap399
Improve
Article Tags :
  • Web Technologies
  • PHP
  • PHP-Misc

Similar Reads

  • How to uncompress a ".tar.gz" file using Python ?
    .tar.gz files are made by the combination of TAR packaging followed by a GNU zip (gzip) compression. These files are commonly used in Unix/Linux based system as packages or installers. In order to read or extract these files, we have to first decompress these files and after that expand them with th
    2 min read
  • How to upload a file in PHP ?
    In this article, we will learn how to upload a file using PHP. Let us first understand some basic configurations. Approach: In your "php.ini" file, search for the "file_uploads" parameter and set it to "On" as mentioned below. file_uploads = On In the "index.html" file, the enctype must be multipart
    3 min read
  • How to read PDF file using PHP ?
    In this article, we will learn how you can show/read PDF file contents on a browser using PHP. We have to include an external PHP file named "class.pdf2text.php". Include it in the required web page using PHP. Create an HTML form, in which we can choose a PDF file from your computer and also check w
    2 min read
  • Unzipping files in Python
    In this article we will see how to unzip the files in python we can achieve this functionality by using zipfile module in Python. What is a zip file ZIP file is a file format that is used for compressing multiple files together into a single file. It is used in an archive file format that supports l
    3 min read
  • How to Zip and Unzip Files in Windows 11?
    Zipping and unzipping files is a common task that helps reduce file size or bundle multiple files together for easier sharing. In this guide, we'll cover 3 easy methods to zip and unzip files in Windows 11 for free. Whether you're using built-in features or looking for quick ways to compress files i
    4 min read
  • How to Unzip .tgz File Using the Linux Terminal?
    If you’ve come across a .tgz file and are unsure how to access its contents, you’re not alone. Knowing how to extract or unzip a .tgz file in a Linux environment can be highly useful, especially when handling compressed files for software installations, backups, or data transfers. Here, we will walk
    6 min read
  • Download file from URL using PHP
    In this article, we will see how to download & save the file from the URL in PHP, & will also understand the different ways to implement it through the examples. Below are the approaches to download file from URL using PHP: Table of Content Using file_get_contents() functionUsing PHP CurlUsi
    3 min read
  • How to write Into a File in PHP ?
    In this article, we are going to discuss how to write into a text file using the PHP built-in fwrite() function. The fwrite() function is used to write into the given file. It stops at the end of the file or when it reaches the specified length passed as a parameter, whichever comes first. The file
    2 min read
  • How to extract or unzip a (7-zip) file with R
    Handling compressed files is quite common while working with data, and to work with various archive formats in the R programming language there are several tools available. Among those formats, the. 7z file format which provides a high compression rate. In this article, we are going to dissect or do
    4 min read
  • PHP | Uploading File
    Have you ever wondered how websites build their system of file uploading in PHP? Here we will come to know about the file uploading process. A question which you can come up with - 'Are we able to upload any kind of file with this system?'. The answer is yes, we can upload files with different types
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences