PHP zip创建函数不能在窗口上工作


php zip creation function is not working on window

我用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";
?>

有谁能帮我一下吗?

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

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

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