0

usually the following script to create and fill a zip archive works properly, both on localhost and on other servers:

$zip = new ZipArchive();
$zip->open($filename, ZipArchive::CREATE);

foreach( $pathToAssets as $nPath ) {
     $files = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator( $nPath ), RecursiveIteratorIterator::LEAVES_ONLY
     );

    foreach ($files as $name => $file) {

        if( $file->getFilename() != '.' && $file->getFilename() != '..' ) {
            $filePath = $file->getRealPath();       
            $temp = explode("/", $name);
            array_shift( $temp );
            $nName = implode("/", $temp);
            $zip->addFile($filePath, $nName);
        }

    }
}

$zip->close()

but in my new server this script instead of creating folders, subfolders and files, only creates files with this name "folder\subfolder\file.extension"

for example: instead of creating a css folder with a bootstrap subfolder which contains the style.css file, it creates a file with the name 'css\bootstrap\style.css'

I can not figure out where to take action on the server to change this behavior. do you have any suggestions for me?

thanks

1 Answers1

0

Method addfile() adds a file to the archive, doesn't create missing directories.

To create directory structure inside the archive use method addEmptyDir()

Mohammed Farag
  • 335
  • 2
  • 9