【问题标题】:php zip creation function is not working on windowphp zip创建功能在窗口上不起作用
【发布时间】:2015-08-29 13:14:07
【问题描述】:

我用 PHP 写了一个 zip 创建函数。它在 Ubuntu 上运行良好,但是当我在 Windows 机器上使用它时会引发错误。

<?php

    $Zip = new ZipArchive();
    $filelocation = 'update';
    $Ziplocation = 'ZipVila/ZipEx.zip';
    $Zipfolder = 'ZipVila';

    $Zip->open($Ziplocation, ZipArchive::CREATE | ZipArchive::OVERWRITE);
    $files = scandir($filelocation);

    print_r($files);

    unset($file[0], $file[1]); // Windows throws an "object file is not defined" error in this line   

    foreach ($files as $file) {

        $Zip->addfile($filelocation."/{$file}", $file);
        echo "File Added";

    }

    $Zip->close();

    echo "Zip Closed";

?>

谁能帮我解决这个问题?

【问题讨论】:

  • 它显示的错误是什么? ZipVila 目录是否存在?目录名称在非 Windows 系统上区分大小写。
  • 目录存在,程序报未创建目标文件的错误

标签: php window


【解决方案1】:

你有一个错误

unset($file[0], $file[1]);

因为 $file 还没有设置,所以你可以取消它,试试这个

unset($files[0], $files[1]);

【讨论】:

  • 请将此标记为正确的解决方案,以便此线程不再存在于未回答部分中。
  • 我也遇到了另一个问题,在 ubantu 上我的代码在我的 zip 中创建了 2 个未知文件,现在问题解决了,非常感谢.....
猜你喜欢
  • 1970-01-01
  • 2017-03-03
  • 2016-12-11
  • 1970-01-01
  • 2016-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多