Create a Zip Archive File Using PHP

Thursday, June 21, 2012

Today we are going to program, How to build a Zip Archive from the Entire Directory or Create Zip file from selected file from server. Here is the solution to Create Zip file with PHP

Following PHP Program you can build Zip file
1 . Zip Entire Directory
2.  Zip Selected Files


$createZipFile=new CreateZipFile;


define("ZIP_DIR",1); // Make it 0 to Archive selected file(s)

//Code toZip a directory and all its files/subdirectories

$fd=fopen($zipName, "wb");

Download This Script     Download Script    


Neil said...

Hi there, thanks for the code but the Download link doesn't work.

Jailani M said...

Hi Neil,
Download link Fixed, you can download now

Neil said...

Thanks Jailani. I have a question, does that script require PHP ZIP extension to be activated?

Jailani M said...

No need, this script works without any server side extensions

Junriel Bonachita said...

Hello Jailani,

Thanks for your code. It works perfect. Just a thought, I want to zipped the folder but not all files. How to do it? I want to exclude some files as they are hard coded files.


sun said...

Hello Jailani

Thanks for your code. It works perfect only zipped the folder but when unzipped the folder following error coming
! C:\Documents and Settings\welcome\My Documents\Downloads\ Unexpected end of archive.

Kindly help me out

A. M. Lechowicz said...

Gonna second that "Unexpected end of archive." error on OS X and Windows

Gayathri said...

The download link I got by email does not work...please help !

Vapes said...

Great Post
For more posts on technology visit Technology blog

Post a Comment