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 ?
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]);