WordPress Plugin: wrap for the script BigDump.php
No php Code edit and no linux command line necessary
getMessage());
echo 'Error on download: ' . $e->getMessage();
}
$zip_file = __DIR__.'/bigdump.zip';
$destination_folder = __DIR__;
try {
bigdump_unzip_file($zip_file, $destination_folder);
// echo 'ZIP file successfully extracted.';
} catch (Exception $e) {
error_log('Error on unzip bigdump.php file: ' . $e->getMessage());
echo 'Error on unzip: ' . $e->getMessage();
}
if(!file_exists('bigdump.inc') and !file_exists('bigdump.php')){
if (isset($_FILES['attachment']['tmp_name']) and is_uploaded_file($_FILES['attachment']['tmp_name'])){
// Determine the file location
$newname = dirname(__FILE__) . '/' .basename($_FILES['attachment']['name']);
if($_FILES['attachment']['name'] == 'bigdump.zip') {
if (!class_exists('ZipArchive')) {
$errors[]='File compressed and unzip class not enabled.';
// return false;
}
else {
if($_FILES['attachment']['size'] <> 12156) {
$errors[]='Wrong File Size. Should be: 12156kb. ';
}
}
}
else {
if($_FILES['attachment']['name'] <> 'bigdump.php') {
$errors[]='Wrong File Name Should be: bigdump.php';
}
if($_FILES['attachment']['size'] <> 40318) {
$errors[]='Wrong File Size. Should be: 40318kb. ';
}
}
if(empty($errors)==true){
// Move the file from temporary location to determined location
if (!(move_uploaded_file($_FILES['attachment']['tmp_name'], $newname))) {
echo "ERROR: A problem occurred during file upload!
\n";
} else {
// echo "The file has been saved as: {$newname}
\n";
}
}
else{
?>
ERROR: A problem occurred during upload file bigdump!
';
}
?>
getMessage());
echo 'Error on unzip: ' . $e->getMessage();
}
}
if(!file_exists('bigdump.inc') and !file_exists('bigdump.php')){
echo '';
echo 'Instructions to upload the script BigDump.php:';
echo 'Please, read!';
echo '';
echo '
';
echo '
';
// var_export($_SERVER['PHP_SELF']);
?>
"/define.+?'DB_NAME'.+?'(.*?)'.+/",
'db_user' => "/define.+?'DB_USER'.+?'(.*?)'.+/",
'db_password' => "/define.+?'DB_PASSWORD'.+?'(.*?)'.+/",
'db_host' => "/define.+?'DB_HOST'.+?'(.*?)'.+/",
];
$return = [];
foreach( $params as $key => $value ) {
$found = preg_match_all( $value, $content, $result );
if( $found ) {
$return[ $key ] = $result[ 1 ][ 0 ];
} else {
$return[ $key ] = false;
}
}
// jun 23
function verificarEnvolturaString($string) {
$primeiroCaractere = substr($string, 0, 1);
$ultimoCaractere = substr($string, -1);
if (($primeiroCaractere != "'" || $ultimoCaractere != "'") && ($primeiroCaractere != '"' || $ultimoCaractere != '"')) {
$string = '"' . addslashes($string) . '"';
}
return $string;
}
$return['db_host'] = verificarEnvolturaString($return['db_host']);
$return['db_name'] = verificarEnvolturaString($return['db_name']);
$return['db_user'] = verificarEnvolturaString($return['db_user']);
$return['db_password'] = verificarEnvolturaString($return['db_password']);
// end jun 23
$path = getcwd();
$filepath = $path .'/bigdump.php';
// $newfilepath = $path .'/bigdump.inc';
$handle = fopen($filepath , 'r+');
$text = fread($handle,filesize($filepath));
//fclose($handle);
$pos = strpos($text, "db_password = ''" );
$new_text = substr($text, 0, $pos+18).PHP_EOL;
$toadd ="
\$db_server = ".$return['db_host'].";
\$db_name = ".$return['db_name'].";
\$db_username = ".$return['db_user'].";
\$db_password = ".$return['db_password'].";
";
$new_text .= $toadd . substr($text, $pos+20);
// step 2
$pos = strpos($new_text, "function skin_open()" );
$new_text2 = substr($new_text, 0, $pos-1);
$toadd = "
require_once('header.inc');
";
$new_text2 .= $toadd . substr($new_text, $pos);
fseek($handle,0);
$r = fwrite($handle, $new_text2, strlen($new_text2) );
fclose($handle);
}
$path = $_SERVER['PHP_SELF'];
$path = str_replace('bigdump-restore.php', 'bigdump.php', $path);
?>
open($file_path) === TRUE) {
$zip->extractTo(dirname($file_path));
$zip->close();
return true;
} else {
return false;
}
} catch (Exception $e) {
return false;
}
}
*/
function bigdump_unzip_file($zip_file, $destination_folder) {
// Check if the ZipArchive library is available
if (!class_exists('ZipArchive')) {
throw new Exception('The ZipArchive library is not available.');
}
// Check if the ZIP file to be extracted exists
if (!file_exists($zip_file)) {
throw new Exception('The ZIP file to be extracted does not exist.');
}
// Start the extraction process within a try-catch block
try {
// Initialize a new instance of the ZipArchive class
$zip = new ZipArchive;
// Open the ZIP file
if ($zip->open($zip_file) === TRUE) {
// Extract the files to the destination directory
$zip->extractTo($destination_folder);
// Close the ZIP file
$zip->close();
// Return true indicating that the extraction was successful
return true;
} else {
// Throw an exception if it's unable to open the ZIP file
throw new Exception('Unable to open the ZIP file.');
}
} catch (Exception $e) {
// Capture any exception occurred during the process and display an error message
throw new Exception('Error extracting the ZIP file: ' . $e->getMessage());
}
}
?>