Are there any specific considerations to keep in mind when using ZipArchive in PHP within a migration context?

When using ZipArchive in PHP within a migration context, it is important to ensure that the paths of the files being added to the archive are relative to the source directory. This is because ZipArchive will store the file paths within the archive, and if they are absolute paths, it may cause issues when extracting the archive on a different server.

$zip = new ZipArchive();
$zip->open('archive.zip', ZipArchive::CREATE);

$files = glob('/path/to/source/directory/*');
foreach ($files as $file) {
    $relativePath = str_replace('/path/to/source/directory/', '', $file);
    $zip->addFile($file, $relativePath);
}

$zip->close();