|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-03-19 00:45 UTC] kolesnikov dot p at hotmail dot com
Description:
------------
In PHP 7 zip archive created with ZipArchive has MIME type 'application/zip'.
In PHP 8 MIME type is 'application/octet-stream'
Test script:
---------------
<?php
unlink('test.zip');
$zip = new ZipArchive();
$zip->open('test.zip', ZipArchive::CREATE);
$zip->addFromString('test.txt', 'file content goes here');
$zip->close();
$info = new finfo(FILEINFO_MIME_TYPE);
echo $info->file('test1.zip') . PHP_EOL;
Expected result:
----------------
application/zip
Actual result:
--------------
PHP7: application/zip
PHP8: application/octet-stream
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 13:00:01 2025 UTC |
Last line echo $info->file('test.zip') . PHP_EOL;This appears to be a problem with zip file versions. File created with command-line zip 3.0: $ file test.zip test.zip: Zip archive data, at least v2.0 to extract File created with the above code on 3 weeks old PHP 8.1-dev: $ file test1.zip test1.zip: Zip archive data, at least v1.0 to extract Then I checked what finfo thinks about these files: $ php -a Interactive shell php > $info = new finfo(FILEINFO_MIME_TYPE); echo $info->file('test1.zip') . PHP_EOL; application/octet-stream php > $info = new finfo(FILEINFO_MIME_TYPE); echo $info->file('test.zip') . PHP_EOL; application/zip But then I rebuilt my PHP with newer changes that include https://github.com/php/php-src/commit/3b9173dc8f3bda99e87003f6b6b2a16fa25c1b72#diff-4371103b525bd66a8f9765a700a60276ee5a5e26115b9aeb190e6657c457862e with friends and it started producing application/zip in both cases. Does that resolve this bug? Does it make sense to backport?