douyousu9691 2016-03-19 02:13
浏览 79

ZipArchive:在addFile()不起作用后使用getFromName()

I'm trying use the method getFromName($name) after I add the file via addFile($name) or addFromString($name, $contents).

On my case, I'm not loading an existing zip file, but I'm creating it in a temporary directory, by using open($name).


The file is added normally and when I do a var_dump() over ZipArchive instance, I get:

class ZipArchive {
  public $status    => int(0)
  public $statusSys => int(0)
  public $numFiles  => int(1)
  public $filename  => string(45) "C:\Temp\Zip576D.tmp"
  public $comment   => string(0)  ""
}

Note that $numFiles shows 1 correctly, and if I call close() it will create file normally with this file added. But if I use getFromName("test") it always returns false instead of file contents.


You can run the code example here: live example

<?php

    $archive = new ZipArchive;
    $archive->addFromString('test.bin', 'test');

    $status = $archive->getFromName('test.bin');

    echo $status === false ? 'FAIL' : 'SUCCESS: ' . $status;

?>

Related: bugs.php.net: Cannot decompress newly added files.

  • 写回答

0条回答 默认 最新

    报告相同问题?