PHP Zip Archive issues

Hi,

anyone using the PHP built-in zip features? having some problems trying to get it to archive files using the addGlob function.

// init code..

$zip->addFile() ; WORKS

// 1st addGlob: WORKS

        $campaign_documents = "./".$dirs['campaign_documents'];
        $options = array('remove_all_path' => TRUE);
        $res = $zip->addGlob($campaign_documents."*", GLOB_BRACE, $options);

// 2nd addGlob FAILS

        $custom_letters = "./".$dirs['custom_letters'];
        $options = array('remove_all_path' => FALSE);
        $res1 = $zip->addGlob($custom_letters."*", GLOB_BRACE, $options);

// this DOES NOT work

Warning: ZipArchive::close(): Can't open file: Permission denied in on line 3362 which is $zip->close();

they are both identical except that the 2nd addGlob has sub-folders with files in them, where as the 1st are only files.
they are both at the identical sub-level

the path looks like

1/custom-letters/5/108/invite.5.108.pdf
1/custom-letters/5/2263/invite.5.2263.pdf
1/custom-letters/5/2266/invite.5.2266.pdf
etc…

$custom_letters builds out to: uploads/ID/custom-letters/ID1/ID2

checking $res1 - it displays only the folder paths, where as the 1st addGlob showed the folder and filenames.

not sure why this is failing, any insights appreciated.

That is because you used array('remove_all_path' => FALSE).

The warning said: Can’t open file: Permission denied, you better check if the files are opened by other program or object (e.g. other zip object in previous code) and the web server user has permissions to open all those files.

yeah, no… flag doesn’t work either way…

don’t think addGlob works properly…

resolved by this:

        $rootPath = "../".$dirs['MY_PATH'];                
        $files = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($rootPath), \RecursiveIteratorIterator::LEAVES_ONLY
        );

        foreach ($files as $file)
        {
            // Skip directories (they would be added automatically)
            if (!$file->isDir())
            {
                // Get real and relative path for current file
                $filePath = @$file->getRealPath();
                $relativePath = substr($filePath, strlen($rootPath) + 6);

                // Add current file to archive
                @$zip->addFile($filePath, $relativePath);
            }
        }        

this works correctly.