![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Zip a directory in PHP?
We can use PHP ZipArchive class in order to zipping and unzipping the folder in PHP. As of PHP 5.3, this class is inbuilt. For using in windows users need to enable php_zip.dll inside of php.ini.
Example
<?php //Enter the name of directory $pathdir = "Directory Name/"; //Enter the name to creating zipped directory $zipcreated = "test.zip"; //Create new zip class $newzip = new ZipArchive; if($newzip -> open($zipcreated, ZipArchive::CREATE ) === TRUE) { $dir = opendir($pathdir); while($file = readdir($dir)) { if(is_file($pathdir.$file)) { $newzip -> addFile($pathdir.$file, $file); } } $newzip ->close(); } ?>
Advertisements