本文整理汇总了PHP中PclZip::open方法的典型用法代码示例。如果您正苦于以下问题:PHP PclZip::open方法的具体用法?PHP PclZip::open怎么用?PHP PclZip::open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PclZip
的用法示例。
在下文中一共展示了PclZip::open方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: backup
function backup()
{
DHDO::logger('Begining Backup.');
global $wpdb;
if (!is_dir(content_url() . '/upgrade/')) {
DHDO::logger('Upgrade folder missing. This will cause serious issues with WP in general, so we will create it for you.');
mkdir(content_url() . '/upgrade/');
}
// Pull in data for what to backup
$sections = get_option('dh-do-backupsection');
if (!$sections) {
$sections = array();
}
$file = WP_CONTENT_DIR . '/upgrade/dreamobject-backups.zip';
$fileurl = content_url() . '/upgrade/dreamobject-backups.zip';
// Pre-Cleanup
if (file_exists($file)) {
@unlink($file);
DHDO::logger('Leftover zip file found, deleting ' . $file . ' ...');
}
try {
$zip = new ZipArchive($file);
$zaresult = true;
DHDO::logger('ZipArchive found and will be used for backups.');
} catch (Exception $e) {
$error_string = $e->getMessage();
$zip = new PclZip($file);
DHDO::logger('ZipArchive not found. Error: ' . $error_string);
DHDO::logger('PclZip will be used for backups.');
require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
$zaresult = false;
}
$backups = array();
// All me files!
if (in_array('files', $sections)) {
DHDO::logger('Calculating backup size...');
$trimdisk = WP_CONTENT_DIR;
$diskcmd = sprintf("du -s %s", WP_CONTENT_DIR);
$diskusage = exec($diskcmd);
$diskusage = trim(str_replace($trimdisk, '', $diskusage));
DHDO::logger(size_format($diskusage * 1024) . ' of diskspace will be processed.');
if ($diskusage < 2000 * 1024) {
$backups = array_merge($backups, DHDO::rscandir(WP_CONTENT_DIR));
DHDO::logger(count($backups) . ' files added to backup list.');
} else {
DHDO::logger('ERROR! PHP is unable to backup your wp-content folder. Please consider cleaning out unused files (like plugins and themes).');
}
if (file_exists(ABSPATH . 'wp-config.php')) {
$backups[] = ABSPATH . 'wp-config.php';
DHDO::logger('wp-config.php added to backup list.');
}
}
// And me DB!
if (in_array('database', $sections)) {
set_time_limit(300);
$sqlhash = wp_hash(wp_rand());
$sqlfile = WP_CONTENT_DIR . '/upgrade/' . $sqlhash . '.sql';
$tables = $wpdb->get_col("SHOW TABLES LIKE '" . $wpdb->prefix . "%'");
$tables_string = implode(' ', $tables);
// Pre cleanup
if (file_exists($sqlfile)) {
@unlink($sqlfile);
DHDO::logger('Leftover sql file found, deleting ' . $sqlfile . ' ...');
}
$dbcmd = sprintf("mysqldump -h'%s' -u'%s' -p'%s' %s %s --single-transaction 2>&1 >> %s", DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, $tables_string, $sqlfile);
exec($dbcmd);
$sqlsize = size_format(@filesize($sqlfile));
DHDO::logger('SQL file created: ' . $sqlfile . ' (' . $sqlsize . ').');
$backups[] = $sqlfile;
DHDO::logger('SQL added to backup list.');
}
if (!empty($backups)) {
set_time_limit(300);
// Increased timeout to 5 minutes. If the zip takes longer than that, I have a problem.
if ($zaresult != 'true') {
DHDO::logger('Creating zip file using PclZip.');
DHDO::logger('NOTICE: If the log stops here, PHP failed to create a zip of your wp-content folder. Please consider increasing the server\'s PHP memory, RAM or CPU.');
$zip->create($backups);
} else {
DHDO::logger('Creating zip file using ZipArchive.');
DHDO::logger('NOTICE: If the log stops here, PHP failed to create a zip of your wp-content folder. Please consider cleaning out unused files (like plugins and themes), or increasing the server\'s PHP memory, RAM or CPU.');
try {
$zip->open($file, ZipArchive::CREATE);
$trimpath = ABSPATH;
foreach ($backups as $backupfiles) {
if (strpos($backupfiles, DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR) === false) {
$zip->addFile($backupfiles, 'dreamobjects-backup' . str_replace($trimpath, '/', $backupfiles));
//DHDO::logger( $backupfiles );
}
}
$zip->close();
} catch (Exception $e) {
$error_string = $e->getMessage();
DHDO::logger('ZipArchive failed to complete: ' . $error_string);
}
}
if (@file_exists($file)) {
DHDO::logger('Calculating zip file size ...');
$zipsize = size_format(@filesize($file));
DHDO::logger('Zip file generated: ' . $file . ' (' . $zipsize . ').');
//.........这里部分代码省略.........