-1

I wrote a zip creation function in PHP. It works fine on Ubuntu but when I it throws an error when I use it on a Windows machine.

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

?>

Can anyone help me in this ?

2
  • What is the error it shows? Does the directory ZipVila exist? Dir name is case sensitive on non windows systems. Aug 29, 2015 at 16:00
  • Directory exists and the program gives the error that the object file is not created Aug 30, 2015 at 10:42

1 Answer 1

-1

you have an error in

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

because $file is not set yet so you can unset it, try this

unset($files[0], $files[1]);
2
  • please mark this as the correct solution so this thread no more exists in the unanswered section. Aug 31, 2015 at 4:55
  • also i was having another problem that on ubantu my code was creating 2 unknown files in my zip and now that problem solved to, thank you so much..... Aug 31, 2015 at 4:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.