Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php ziparchive compress folder

<?php
class FlxZipArchive extends ZipArchive 
{
 public function addDir($location, $name) 
 {
       $this->addEmptyDir($name);
       $this->addDirDo($location, $name);
 } 
 private function addDirDo($location, $name) 
 {
    $name .= '/';
    $location .= '/';
    $dir = opendir ($location);
    while ($file = readdir($dir))
    {
        if ($file == '.' || $file == '..') continue;
        $do = (filetype( $location . $file) == 'dir') ? 'addDir' : 'addFile';
        $this->$do($location . $file, $name . $file);
    }
 } 
}
?>

<?php
$the_folder = '/path/to/folder/to/be/zipped';
$zip_file_name = '/path/to/zip/archive.zip';
$za = new FlxZipArchive;
$res = $za->open($zip_file_name, ZipArchive::CREATE);
if($res === TRUE) 
{
    $za->addDir($the_folder, basename($the_folder));
    $za->close();
}
else{
echo 'Could not create a zip archive';
}
?>
Comment

PREVIOUS NEXT
Code Example
Php :: php artisan vendor:publish 
Php :: laravel route slug 
Php :: change woocommerce return to shop link 
Php :: replace accent php 
Php :: a facade root has not been set laravel 
Php :: mysqli real escape string php 
Php :: laravel model create array 
Php :: php sum array of objects 
Php :: best pagination in laravel api with eloquent 
Php :: woocommerce get product categories 
Php :: multiply a string php 
Php :: php get last part of url 
Php :: publish Laravel mail pages to customize 
Php :: PHP Numeric String 
Php :: api anaf 
Php :: file to binary php 
Php :: showing php code in browser 
Php :: laravel blade variable isset, empty or optional 
Php :: how to replace double quotes in a string in php 
Php :: how to backup laravel project 
Php :: larave artisan command run in web 
Php :: Custom Product Price in Loop of Woocomare 
Php :: laravel clear page cache 
Php :: simple localhost php 
Php :: php show active page 
Php :: Deleting an element from an array in PHP 
Php :: laravel cron job on shared hosting 
Php :: laravel insert timestamp now 
Php :: validation error message in laravel 
Php :: array_push in php 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =