php create zip from folder

Solutions on MaxInterview for php create zip from folder by the best coders in the world

showing results for - "php create zip from folder"
Cristóbal
23 Jan 2016
1<?php
2class FlxZipArchive extends ZipArchive 
3{
4 public function addDir($location, $name) 
5 {
6       $this->addEmptyDir($name);
7       $this->addDirDo($location, $name);
8 } 
9 private function addDirDo($location, $name) 
10 {
11    $name .= '/';
12    $location .= '/';
13    $dir = opendir ($location);
14    while ($file = readdir($dir))
15    {
16        if ($file == '.' || $file == '..') continue;
17        $do = (filetype( $location . $file) == 'dir') ? 'addDir' : 'addFile';
18        $this->$do($location . $file, $name . $file);
19    }
20 } 
21}
22?>
23
24<?php
25$the_folder = '/path/to/folder/to/be/zipped';
26$zip_file_name = '/path/to/zip/archive.zip';
27$za = new FlxZipArchive;
28$res = $za->open($zip_file_name, ZipArchive::CREATE);
29if($res === TRUE) 
30{
31    $za->addDir($the_folder, basename($the_folder));
32    $za->close();
33}
34else{
35echo 'Could not create a zip archive';
36}
37?>
queries leading to this page
create zip file and download in phpzip file download in php pagecreate zip file of a folder and download it phpzip a directory in phphow to create zip file and download in phpphp specify zip fdolder namecompress folder to zipescape folder in zip laravel ziparchievphp zip files in directoryphp ziparchive add directory with fileshow to zip a folder in phpziparchive add folder phpcreate zip phpphp all files zipperphp create zip file from foldermake a full folder zip using phpziparvhivegenerate zip phpphp zip specific folderzip folder phpphp zip folderszip folder using phpcompress a zip folderphp zip files in folderphp create folder zipcreate zip php downloadphp zip add to archive using iteratorphp zip file createphp zip compress folderphp zip directorymake zip of contents of a folder phpphp zip add directory and filesphp creer un zip de documentphp create zip examplephp zip whole cataloguephp zip directory and downloadcreate zip using phpzip file in folder phpzip a folder using phpphp compress folder to zipmake zip folder in phpphp create zip file from directoryzip save direcotry phpphp how to zip a folderget all files from zip in array phpphp make zip file of directoryphp add all file and folder to zipphp zip get path of files and foldershow to create specific folder inside zip in phpphp create zip file of folderphp compress folder to zip and downloadphp add all file to zipphp zip entire foldercreate zip file of folder in phpall files from zip in array phpphp function to create the zip file of folderhow to zip contents of a folder phpziparchive zip folder phpphp function to create zip filecreate zip folder and download in phpziparchive add foldercompress file using ziparchive in phpphp zip a folderphp create zip and add all files in folderphp zip file in foldercheck ziparchive in phpinfojs create zip photo download upper folder phpcreate zip on other directory phphow to compress my php and html file folders 24zip 3eadd folder phpphp create zip filephp create zip from folder php zip get path of filescreate the folder zip file in phpcreate zip files phpphp add to zip inside a folderzip and compress fiolderphp zip mention zip folder namephp create zip file and storecopy file from different folders and zip in phpcreate zip file phpcreate zip with all files and folder phphow t ozip folder in phpcreate zip file and download using phpphp creating zip from foldercompress files to zip folder download free zip addfile phpphp how to stream a zip filephp all file and folder zipphp ziparchive zip all zip filescreate zip in phpphp make zip filesphp zip folderphp script zip all files directoryphp generate zipphp zip create folderzip folder with phpcrete zip file from files and folders phpphp ziparchive compress folderphp create zip from folder