//备份
public function todo(){
//打包文件,将备份文件保存到backup文件夹
$filename = date('YmdHis').'.php';
$zip = new \ZipArchive();
if($zip->open('backup/'.$filename, \ZIPARCHIVE::CREATE) !== TRUE) {
die("无法创建 $filename");
}
$this->backup_folder('.', $zip);
$zip->close();
//获取备份文件的完整路径
$filepath = realpath('backup/'.$filename);
echo "备份成功!";
}
public function backup_folder($folder, $archive) {
$folder .= '/';
$files = glob($folder . '*', GLOB_MARK);
foreach($files as $file) {
if(is_dir($file)) {
$this->backup_folder($file, $archive);
} else {
$archive->addFile($file);
}
}
}