I want to add to the archive a folder in which there are subfolders and files in them.
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); I can not use this, because I do not need all the files.
There is an array with some information about the files:
$paths = [ [ 'name' => 'file', 'ext' => 'txt', 'path' => '/folder/' ], [ 'name' => 'subFolder', 'ext' => 'folder', 'path' => '/folder/' ], [ 'name' => 'fileInSubFolder', 'ext' => 'txt', 'path' => '/folder/subFolder/' ] ]; In the loop I do a check:
if( $folder[$i]['ext'] == 'folder' ) $zip->addEmptyDir($fileName); else $zip->addFromString( $fileName.$fileExt, file_get_contents($fileFullPath.$fileExt)); If the "folder", then create an empty folder in the archive, otherwise I add the file to the archive. Only if the file is in a subfolder, is it added to the root of the archive, and how to add it to the subfolder? Or how to change the current directory to add?