本文整理汇总了PHP中AIOWPSecurity_Utility_File::create_dir方法的典型用法代码示例。如果您正苦于以下问题:PHP AIOWPSecurity_Utility_File::create_dir方法的具体用法?PHP AIOWPSecurity_Utility_File::create_dir怎么用?PHP AIOWPSecurity_Utility_File::create_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AIOWPSecurity_Utility_File
的用法示例。
在下文中一共展示了AIOWPSecurity_Utility_File::create_dir方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: backup_and_rename_htaccess
static function backup_and_rename_htaccess($src_file_path, $suffix = 'backup')
{
global $aio_wp_security;
//Check to see if the main "backups" directory exists - create it otherwise
$aiowps_backup_dir = WP_CONTENT_DIR . '/' . AIO_WP_SECURITY_BACKUPS_DIR_NAME;
if (!AIOWPSecurity_Utility_File::create_dir($aiowps_backup_dir)) {
$aio_wp_security->debug_logger->log_debug("backup_and_rename_htaccess - Creation of backup directory failed!", 4);
return false;
}
$src_parts = pathinfo($src_file_path);
$backup_file_name = $src_parts['basename'] . '.' . $suffix;
$backup_file_path = $aiowps_backup_dir . '/' . $backup_file_name;
if (!copy($src_file_path, $backup_file_path)) {
//Failed to make a backup copy
return false;
}
return true;
}
示例2: execute_backup
/**
* This function will perform a database backup
*/
function execute_backup()
{
global $wpdb, $aio_wp_security;
$is_multi_site = false;
@ini_set('auto_detect_line_endings', true);
if (function_exists('is_multisite') && is_multisite()) {
//Let's get the current site's table prefix
$site_pref = esc_sql($wpdb->prefix);
$db_query = "SHOW TABLES LIKE '" . $site_pref . "%'";
$tables = $wpdb->get_results($db_query, ARRAY_N);
$is_multi_site = true;
} else {
//get all of the tables
$tables = $wpdb->get_results('SHOW TABLES', ARRAY_N);
if (empty($tables)) {
$aio_wp_security->debug_logger->log_debug("execute_backup() - no tables found!", 4);
return FALSE;
}
}
$return = '';
//cycle through each table
foreach ($tables as $table) {
$result = $wpdb->get_results('SELECT * FROM `' . $table[0] . '`;', ARRAY_N);
$num_fields = sizeof($wpdb->get_results('DESCRIBE `' . $table[0] . '`;'));
$return .= 'DROP TABLE IF EXISTS `' . $table[0] . '`;';
$row2 = $wpdb->get_row('SHOW CREATE TABLE `' . $table[0] . '`;', ARRAY_N);
if (empty($row2)) {
$aio_wp_security->debug_logger->log_debug("execute_backup() - get_row returned NULL for table: " . $table[0], 4);
}
$return .= PHP_EOL . PHP_EOL . $row2[1] . ";" . PHP_EOL . PHP_EOL;
foreach ($result as $row) {
$return .= 'INSERT INTO `' . $table[0] . '` VALUES(';
for ($j = 0; $j < $num_fields; $j++) {
$row[$j] = addslashes($row[$j]);
//$row[$j] = ereg_replace( PHP_EOL, "\n", $row[$j] ); //deprecated!
$row[$j] = preg_replace("/" . PHP_EOL . "/", "\n", $row[$j]);
if (isset($row[$j])) {
$return .= '"' . $row[$j] . '"';
} else {
$return .= '""';
}
if ($j < $num_fields - 1) {
$return .= ',';
}
}
$return .= ");" . PHP_EOL;
}
$return .= PHP_EOL . PHP_EOL;
}
$return .= PHP_EOL . PHP_EOL;
//Check to see if the main "backups" directory exists - create it otherwise
$aiowps_backup_dir = WP_CONTENT_DIR . '/' . AIO_WP_SECURITY_BACKUPS_DIR_NAME;
$aiowps_backup_url = content_url() . '/' . AIO_WP_SECURITY_BACKUPS_DIR_NAME;
if (!AIOWPSecurity_Utility_File::create_dir($aiowps_backup_dir)) {
$aio_wp_security->debug_logger->log_debug("Creation of DB backup directory failed!", 4);
return false;
}
//Generate a random prefix for more secure filenames
$random_suffix = AIOWPSecurity_Utility::generate_alpha_numeric_random_string(10);
if ($is_multi_site) {
global $current_blog;
$blog_id = $current_blog->blog_id;
//Get the current site name string for use later
$site_name = get_bloginfo('name');
$site_name = strtolower($site_name);
//make alphaunermic
$site_name = preg_replace("/[^a-z0-9_\\s-]/", "", $site_name);
//Cleanup multiple instances of dashes or whitespaces
$site_name = preg_replace("/[\\s-]+/", " ", $site_name);
//Convert whitespaces and underscore to dash
$site_name = preg_replace("/[\\s_]/", "-", $site_name);
$file = 'database-backup-site-name-' . $site_name . '-' . current_time('Ymd-His') . '-' . $random_suffix;
//We will create a sub dir for the blog using its blog id
$dirpath = $aiowps_backup_dir . '/blogid_' . $blog_id;
//Create a subdirectory for this blog_id
if (!AIOWPSecurity_Utility_File::create_dir($dirpath)) {
$aio_wp_security->debug_logger->log_debug("Creation failed of DB backup directory for the following multisite blog ID: " . $blog_id, 4);
return false;
}
} else {
$dirpath = $aiowps_backup_dir;
$file = 'database-backup-' . current_time('Ymd-His') . '-' . $random_suffix;
}
$handle = @fopen($dirpath . '/' . $file . '.sql', 'w+');
$fw_res = @fwrite($handle, $return);
if (!$fw_res) {
$aio_wp_security->debug_logger->log_debug("execute_backup() - Write to DB backup file failed", 4);
return false;
}
@fclose($handle);
//zip the file
if (class_exists('ZipArchive')) {
$zip = new ZipArchive();
$archive = $zip->open($dirpath . '/' . $file . '.zip', ZipArchive::CREATE);
$zip->addFile($dirpath . '/' . $file . '.sql', $file . '.sql');
$zip->close();
//delete .sql and keep zip
//.........这里部分代码省略.........