What potential issues can arise when trying to pack files using ZipArchive in PHP?

One potential issue when trying to pack files using ZipArchive in PHP is running out of memory if you are trying to compress a large number of files or files that are too large. To solve this issue, you can increase the memory limit in your PHP configuration or try to optimize the files being compressed to reduce their size.

// Increase memory limit
ini_set('memory_limit', '256M');

// Create a new ZipArchive object
$zip = new ZipArchive();

// Open a zip file
if ($zip->open('archive.zip', ZipArchive::CREATE) === TRUE) {
    // Add files to the zip file
    $zip->addFile('file1.txt');
    $zip->addFile('file2.txt');
    
    // Close the zip file
    $zip->close();
} else {
    echo 'Failed to create zip file';
}