I'm trying to backup my site by zipping it all, and putting the zip into an unnaccessible folder, done with PHP. My code is
<?php
Zip('../../', './');
function Zip($source, $destination)
{
if (extension_loaded('zip') === true)
{ echo'a';
if (file_exists($source) === true)
{
$zip = new ZipArchive();
if ($zip->open($destination, ZIPARCHIVE::CREATE) === true)
{
$source = realpath($source);
if (is_dir($source) === true)
{
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file)
{
$file = realpath($file);
if (is_dir($file) === true)
{
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
}
else if (is_file($file) === true)
{
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
}
else if (is_file($source) === true)
{
$zip->addFromString(basename($source), file_get_contents($source));
}
}
return $zip->close(); // The error.
}
}
return false;
}
?>
But I get an error of Warning: ZipArchive::close() [ziparchive.close]: Invalid or unitialized Zip object in backup.php on line 41
I have searched google, and no results.