MiX1.TK
Site menu
Login form
Section categories
Web Development [20]
Learn about PHP & Web Development
Education [4]
Learn for Free
Knowledge & Tricks [0]
General Knowledge,computer Knowledge & tricks
Writing World [2]
A MiX World of SmS on Various Topics
Search
Main » 2012 » November » 6 » How to make a zip archiev in php scripting language
9:47 PM
How to make a zip archiev in php scripting language
<?php
function folderToZip($folder, &$zipFile, $subfolder = null) {
    if (
$zipFile == null) {
       
// no resource given, exit
       
return false;
    }
   
// we check if $folder has a slash at its end, if not, we append one
   
$folder .= end(str_split($folder)) == "/" ? "" : "/";
   
$subfolder .= end(str_split($subfolder)) == "/" ? "" : "/";
   
// we start by going through all files in $folder
   
$handle = opendir($folder);
    while (
$f = readdir($handle)) {
        if (
$f != "." && $f != "..") {
            if (
is_file($folder . $f)) {
               
// if we find a file, store it
                // if we have a subfolder, store it there
               
if ($subfolder != null)
                   
$zipFile->addFile($folder . $f, $subfolder . $f);
                else
                   
$zipFile->addFile($folder . $f);
            } elseif (
is_dir($folder . $f)) {
               
// if we find a folder, create a folder in the zip
               
$zipFile->addEmptyDir($f);
               
// and call the function again
               
folderToZip($folder . $f, $zipFile, $f);
            }
        }
    }
}
?>

Use it like this:
<?php
$z
= new ZipArchive();
$z->open("test.zip", ZIPARCHIVE::CREATE);
folderToZip("storeThisFolder", $z);
$z->close();
?>
Category: Web Development | Views: 286 | Added by: admin-priyank | Rating: 5.0/1
Total comments: 0
Name *:
Email *:
Code *:
Calendar
«  November 2012  »
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
252627282930
Entries archive
Our poll
Rate my site
Total of answers: 4
Site friends
  • Create a free website
  • Online Desktop
  • Free Online Games
  • Video Tutorials
  • All HTML Tags
  • Browser Kits
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    Creative Commons License
    Free Downloads and Services by MiX1 is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
    Copyright MyCorp © 2024