Package version 7.10.1
After do a composer update on my project i have this issue, this occurs when i try to download a zip file of a collection of images, in previous version before update it worked fine
i do something like
public function __invoke(Request $request, Mission $mission): MediaStream
{
$files = $mission->getMedia('images');
return MediaStream::create($mission->name.'.zip')->addMedia($files);
}
And i got this


@rubenvanassche could you take a look?
This error still persist on version 7.12.0
New to all this coding stuff but after a quick Google it looks like
Their is nothing open for fclose() to close.
If I'm wrong then sorry just trying to get started with opensource dev :-)
Maybe fopen($stream) in line 68 after creating the $stream variable.
Hi @piryguiry I guess @m-rufflesmcghie is right, there is nothing in the stream. So I think you should check if the files you're trying to put in the zip archive still exist. You could also try to change line 71 from /vendor/spatie/laravel-medialibrary/src/MediaStream.phpto something like this:
if($stream ! == null){
fclose($stream);
}
If that solves the problem it means the stream was not created or created correctly. Let me know if this is the case, maybe we should upgrade the package then.
@rubenvanassche I been following the recommendation, i check the files that i trying to put in the zip, all good at this part.

I change the line that you're mention, i was did something similar before. but i get the same error.

Having the exact same problem when trying to download a zip file.
If it helps, for some reason it seems to work fine on my production app with php 7.1 but not on the one with php 7.3
Edit: Also, single downloads, files URLs and visualization on app work fine, it's only the zip download which is having trouble.
@rubenvanassche, @rnbroggi Yes it's only the zip download fails, in my case on production runs fine with php 7.3.9, and the package version 7.6.0, but after update have this issue.
@piryguiry Yup, switched back to V7.6.0 and works. Looks like there's indeed an issue with the new version
Same here. I just rolled back from 7.9 -> 7.6 and it started working again. Had the same issue.
7.6.3 works for me, after that the newer versions has this issue or the imagick error message. I'm using PHP 7.3 and Laravel 5.8 if it helps
I ran into both of these problems today.
The first was "solved" by checking is_resource before attempting fclose()
if (is_resource($stream)) {
fclose($stream);
}
The second problem is related to Zipstream not sending any HTTP headers by default, which leads to the binary zip data being shown directly in browser:
$options = new \ZipStream\Option\Archive();
// Send http headers (default is false)
$options->setSendHttpHeaders(true);
// HTTP Content-Disposition. Defaults to 'attachment', where FILENAME is the specified filename. Note that this does nothing if you are not sending HTTP headers.
$options->setContentDisposition('attachment');
// Set the content type (does nothing if you are not sending HTTP headers)
// $options->setContentType('application/octet-stream');
$options->setContentType('application/x-zip');
The "problem" would appear to not be related to laravel-medialibrary specifically. I tried with just enabling setSendHttpHeaders but it still showed in browser.
This is not a bug and enables another feature I've been trying to get working - streaming large files from one S3 bucket into another S3 bucket as a zip file.
References:
Hi, guys I was on vacation but looking into this today!
The fix by @rubenvanassche is now merged and tagged. This problem is fixed in v7.12.3 of the package.
Most helpful comment
The fix by @rubenvanassche is now merged and tagged. This problem is fixed in v7.12.3 of the package.