What are the potential pitfalls of using ZipArchive::addFromString for adding images to a zip archive in PHP?

Potential pitfalls of using ZipArchive::addFromString for adding images to a zip archive in PHP include loss of image quality and incorrect file format detection. To avoid these issues, it is recommended to use ZipArchive::addFile instead, which allows you to specify the file path directly.

$zip = new ZipArchive;
if ($zip->open('images.zip', ZipArchive::CREATE) === TRUE) {
    $imagePath = 'image.jpg';
    $zip->addFile($imagePath, basename($imagePath));
    $zip->close();
    echo 'Images added to zip archive successfully.';
} else {
    echo 'Failed to create zip archive.';
}