maennchen/ZipStream-PHP

Unexpected filename when outputName given in constructor

Opened this issue · 2 comments

ZipStream-PHP version

3.1.1

PHP version

8.3.9

Constraints for Bug Report

Summary

There is unexpected prefix when outputName is set in ZipStream constructor.
Looks like the issue is in ZipStream class in sendHttpHeaders function.

Current behavior

When I set outputName in constructor, I got file with name UTF-8''<my filename from variable> which is unexpected behaviour for me. Workaround is to set contentDisposition with content like "attachment; filename*={$fileName}",

How to reproduce

$zip = new ZipStream(
    contentType: 'application/octet-stream',
    outputName: "{$fileName}",
);

foreach ($files as $filePath) {
    try {
        $streamRead = fopen('php://temp', 'r+');
        $remoteStreamRead = fopen($filePath['url'], 'r');
        stream_copy_to_stream($remoteStreamRead, $streamRead);
        rewind($streamRead);
    } catch (\Throwable $exception) {
    }

    $zip->addFileFromStream($filePath['filename'], $streamRead);
}

Expected behavior

Output filename should not contain UTF-8'' prefix by default

The header follows the RFC 5987:
https://www.rfc-editor.org/rfc/rfc5987#section-3.2.2

It seems your HTTP client does not follow that specification. What browser are you using?

Hey @maennchen
I use Chrome 130.0.6723.92