
Following PHP Program you can build Zip file
1 . Zip Entire Directory
2. Zip Selected Files
<?php include_once("CreateZipFile.inc.php"); $createZipFile=new CreateZipFile; $directoryToZip="./"; $outputDir="/"; $zipName="CreateZipFileWithPHP.zip"; define("ZIP_DIR",1); // Make it 0 to Archive selected file(s) if(ZIP_DIR) { //Code toZip a directory and all its files/subdirectories $createZipFile->zipDirectory($directoryToZip,$outputDir); }else { $fileToZip1="files/File1.txt"; $fileToZip2="files/File2.txt"; $createZipFile->addFile(file_get_contents($fileToZip1),$fileToZip1); $createZipFile->addFile(file_get_contents($fileToZip2),$fileToZip2); $createZipFile->addFile(file_get_contents($fileToZip3),$fileToZip3); } $fd=fopen($zipName, "wb"); $out=fwrite($fd,$createZipFile->getZippedfile()); fclose($fd); $createZipFile->forceDownload($zipName); @unlink($zipName); ?>
![]() |
Download Script | |
Hi there, thanks for the code but the Download link doesn't work.
ReplyDeleteHi Neil,
ReplyDeleteDownload link Fixed, you can download now
Thanks Jailani. I have a question, does that script require PHP ZIP extension to be activated?
ReplyDeleteNo need, this script works without any server side extensions
ReplyDeleteHello Jailani,
ReplyDeleteThanks 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.
Thanks
Hello Jailani
ReplyDeleteThanks 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\CreateZipFileWithPHP1.zip: Unexpected end of archive.
Kindly help me out
Gonna second that "Unexpected end of archive." error on OS X and Windows
ReplyDeleteThe download link I got by email does not work...please help !
ReplyDeleteGreat Post
ReplyDeletethanks
For more posts on technology visit Technology blog