【问题标题】:fails with ZipArchiveZipArchive 失败
【发布时间】:2018-07-14 01:23:21
【问题描述】:

我将使用 PHP 类创建一个 Zip 存档。但它仍然无法正常工作。 它没有失败,响应是 1。他没有创建 Zip-File。

$zip = new ZipArchive;
$res = $zip->open('qr_img/'.'ab387bas.zip'.'', ZipArchive::CREATE);
if ($res === TRUE) {
    $zip->addFile($file, 'screen.png');
    $zip->close();
}

大家都知道答案吗?

【问题讨论】:

  • 看看我的这个答案:stackoverflow.com/questions/15381142/…响应“1”实际上是一个错误代码,在互联网上寻找它。
  • 这里是,在页面底部:php.net/manual/en/zip.constants.php if $res == 1 表示Multi-disk zip archives not supported
  • 谢谢,但是我能做些什么呢?
  • 如果zip是自己生成的,直接生成就行了,不是多盘。如果 zip 存档应该由用户上传,请向他们显示相同的消息。

标签: php html mysql css


【解决方案1】:

$file_names 是您要添加到 zip 中的文件数组。

 function zipFile($file_names,$archive_file_name)
{
    $zip = new ZipArchive();
    //create the file and throw the error if unsuccessful
    if ($zip->open($archive_file_name, ZIPARCHIVE::OVERWRITE )!==TRUE) {

    }

    //add each files of $file_name array to archive
    foreach($file_names as $files)
    {
    //  $zip->addFile($files,$files);
        $zip->addFromString(basename($files),  file_get_contents($files));
    }
    $zip->close();


}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-15
    • 2018-11-01
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多