maennchen / ZipStream-PHP

:floppy_disk: PHP ZIP Streaming Library
https://maennchen.dev/ZipStream-PHP/
MIT License
1.76k stars 105 forks source link

Unexpected filename when outputName given in constructor #316

Open bartiii opened 1 week ago

bartiii commented 1 week ago

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

maennchen commented 1 week ago

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?

bartiii commented 1 week ago

Hey @maennchen I use Chrome 130.0.6723.92