note 86188 added to function.ziparchive-addemptydir

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
I've brought a little modification to dayjo's code, so it wouldn't re-create the whole structure of your working drive in the zip file:

<?php
// Function to recursively add a directory,
// sub-directories and files to a zip archive
function addFolderToZip($dir, $zipArchive, $zipdir = ''){
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {

            //Add the directory
            $zipArchive->addEmptyDir($dir);
           
            // Loop through all the files
            while (($file = readdir($dh)) !== false) {
           
                //If it's a folder, run the function again!
                if(!is_file($dir . $file)){
                    // Skip parent and root directories
                    if( ($file !== ".") && ($file !== "..")){
                        addFolderToZip($dir . $file . "/", $zipArchive, $zipdir . $file . "/");
                    }
                   
                }else{
                    // Add the files
                    $zipArchive->addFile($dir . $file, $zipdir . $file);
                   
                }
            }
        }
    }
}
?>

If you don't specify the third parameter (zipdir), the directory you're adding will be added at the root of the zip file.

D.Jann
----
Server IP: 89.31.146.176
Probable Submitter: 212.74.185.158
----
Manual Page -- http://www.php.net/manual/en/function.ziparchive-addemptydir.php
Edit        -- https://master.php.net/note/edit/86188
Del: integrated  -- https://master.php.net/note/delete/86188/integrated
Del: useless     -- https://master.php.net/note/delete/86188/useless
Del: bad code    -- https://master.php.net/note/delete/86188/bad+code
Del: spam        -- https://master.php.net/note/delete/86188/spam
Del: non-english -- https://master.php.net/note/delete/86188/non-english
Del: in docs     -- https://master.php.net/note/delete/86188/in+docs
Del: other reasons-- https://master.php.net/note/delete/86188
Reject      -- https://master.php.net/note/reject/86188
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.