php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79157 Documentation unclear for ZipArchive::setCompressionName
Submitted: 2020-01-22 19:30 UTC Modified: 2020-01-22 22:28 UTC
From: kris dot rande at infinite dot com Assigned:
Status: Open Package: Zip Related
PHP Version: 7.4.1 OS: Ubuntu 16
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-01-22 19:30 UTC] kris dot rande at infinite dot com
Description:
------------
---
From manual page: https://php.net/ziparchive.setcompressionname
---

The documentation for ZipArchive::setCompressionName is unclear about what to pass for the $name parameter.

I wrongly assumed the $name parameter was the path to the source file ($filename parameter when calling ZipArchive::addFile). Through experimentation I determined it is actually the local name (optional $localname parameter when calling ZipArchive::addFile).

This could be improved by using "$localname" in all ZipArchive methods.

It would also be helpful to provide a code example that shows ZipArchive::addFile and ZipArchive::setCompressionName used together. I've included a proposed example in the "Test script" section below.

Test script:
---------------
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
    $zip->addFile('foo.jpg', 'foo', 'Some text');
    $zip->setCompressionName('foo', ZipArchive::CM_STORE);
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-22 22:28 UTC] cmb@php.net
-Package: zip +Package: Zip Related
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Feb 18 16:01:27 2020 UTC