laravel-zipstream icon indicating copy to clipboard operation
laravel-zipstream copied to clipboard

Files inside the zip are corrupted

Open damarinov1 opened this issue 4 months ago • 0 comments

Laravel 10 PHP 8.2

Hi,

I am updating a project that is using your library since version 2.4. Now, I am updating up to Laravel 10 and updated your library to the latest version (5.0.2).

I am using the library to zip XLSX files that are generated from reports. For some reason, after the update, now, the files inside the zip are not stored correctly and corrupted. The zip size is 632 bytes and the files inside are 71 bytes. Here's how I am using it:

// Method declaration and some code above
                $zip = Zip::create($zipFileName);

                for ($i = 1; $i <= $batch; $i++) {
                    $batchFileName = $i . '-' . $fileName;

                    if ($this->reportsStorage->exists($batchFileName)) {
                        $zip->add($this->reportsStorage->url($batchFileName), $batchFileName);
                    }
                }                
                
                $path = config('filesystems.disks.' . config('filesystems.disk_names.reports') . '.root');
                $zip->saveTo($path);
// Some code below

I've tried the same exact logic from above, manually in tinker. The zip was perfect. For some reason, during code execution something is happening that I cannot catch.

Any ideas, suggestions what could I be missing? Some config?

Edit: I saw that it doesn't like Spatie's media library. In what sense they are in conflict? Here, in this example these files are not in any way using the media library.

Thanks in advance.

Edit2: I've edited the path to the file. Before I was sending relative url to the files, for example storage/reports/test.xlsx and I've changed it to full url (https://localhost/storage/reports/test.xlsx)

And now when I get to save the zip I've got this error

Typed property STS\ZipStream\Models\File::$filesize must not be accessed before initialization 

What does this error mean? Any help would be appreaciated

damarinov1 avatar Oct 10 '24 13:10 damarinov1