我想要做的是创建一个 zip 文件
public function createFilesBackup()
{
$dir = home_path();
$sitePath = realpath($dir);
$zip = new ZipArchive();
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($sitePath),
RecursiveIteratorIterator::LEAVES_ONLY
);
$zipName = 'backup_'.date('Y-m-d').'.zip';
$zipfileName = $sitePath."/wp-content/uploads/".$zipName;
$zip->open($zipfileName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
foreach ($files as $name => $file)
{
if (!$file->isDir())
{
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($sitePath) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
return get_site_url()."/".$zipName;
}
这就是我得到的任何人都可以帮助我我会很棒
致命错误:未捕获的 RuntimeException:SplFileInfo::isDir():open_basedir 限制生效。文件(/home/abdulbasit/web/checkout-demo.wholisticleather.com/public_html/..)不在允许的路径内:(/home/abdulbasit/web/checkout-demo.wholisticleather.com/public_html: /home/abdulbasit/tmp) 在 /home/abdulbasit/web/checkout-demo.wholisticleather.com/public_html/wp-content/plugins/MerchantypayWPBackup/MerchantypayWPBackup.php:66 堆栈跟踪:#0 /home/abdulbasit/web/ checkout-demo.wholisticleather.com/public_html/wp-content/plugins/MerchantypayWPBackup/MerchantypayWPBackup.php(66): SplFileInfo->isDir() #1 /home/abdulbasit/web/checkout-demo.wholisticleather.com/public_html/ wp-content/plugins/MerchantypayWPBackup/cron.php(23): MerchantypayWPBackup->createFilesBackup('/home/abdulbasi...', '/home/abdulbasi...'