function Converter($filesource, $filedestination, $cp) { global $config, $lang; $filesize = 0; $max_filesize = 1024 * 1024 * 10; //10 MB splitsize $part = 1; $cps = substr(strtolower($filesource), -2) == "gz" ? 1 : 0; $filedestination .= '_' . date("Y_m_d_H_i", time()); echo "<h5>" . sprintf($lang['L_CONVERT_FILEREAD'], $filesource) . ".....</h5><span style=\"font-size:10px;\">"; if (file_exists($config['paths']['backup'] . $filedestination)) { unlink($config['paths']['backup'] . $filedestination); } $f = $cps == 1 ? gzopen($config['paths']['backup'] . $filesource, "r") : fopen($config['paths']['backup'] . $filesource, "r"); $z = $cp == 1 ? gzopen($config['paths']['backup'] . $filedestination . '_part_1.sql.gz', "w") : fopen($config['paths']['backup'] . $filedestination . '_part_1.sql', "w"); $zeile = get_pseudo_statusline($part, $filedestination) . "\r\n"; $cp == 1 ? gzwrite($z, $zeile) : fwrite($z, $zeile); $zeile = ''; $insert = $mode = ""; $n = 0; $eof = $cps == 1 ? gzeof($f) : feof($f); $splitable = false; // can the file be splitted? Try to avoid splitting before a command is completed while (!$eof) { $eof = $cps == 1 ? gzeof($f) : feof($f); $zeile = $cps == 1 ? gzgets($f, 5144000) : fgets($f, 5144000); $t = strtolower(substr($zeile, 0, 10)); if ($t > '') { switch ($t) { case 'insert int': // eine neue Insert Anweisung beginnt if (strpos($zeile, '(') === false) { //Feldnamen stehen in der naechsten Zeile - holen $zeile .= "\n\r"; $zeile .= $cps == 1 ? trim(gzgets($f, 8192)) : trim(fgets($f, 8192)); $zeile .= ' '; } // get INSERT-Satement $insert = substr($zeile, 0, strpos($zeile, '(')); if (substr(strtoupper($insert), -7) != 'VALUES ') { $insert .= ' VALUES '; } $mode = 'insert'; $zeile = "\n\r" . $zeile; $splitable = false; break; case 'create tab': $mode = 'create'; while (substr(rtrim($zeile), -1) != ';') { $zeile .= fgets($f, 8192); } $zeile = "\n\r" . MySQL_Ticks($zeile) . "\n\r"; $splitable = true; break; } } if ($mode == 'insert') { if (substr(rtrim($zeile), strlen($zeile) - 3, 2) == ');') { $splitable = true; } // Komma loeschen $zeile = str_replace('),(', ");\n\r" . $insert . ' (', $zeile); } if ($splitable == true && $filesize > $max_filesize) { $part++; if ($mode == 'insert') { if ($cp == 1) { gzwrite($z, $zeile); gzclose($z); $z = gzopen($config['paths']['backup'] . $filedestination . '_part_' . $part . '.sql.gz', "w"); $zeile = get_pseudo_statusline($part, $filedestination) . "\r\n"; gzwrite($z, $zeile); $zeile = ''; } else { fwrite($z, $zeile); echo "<br>Neue Datei.Zeile: <br>" . htmlspecialchars(substr($zeile, 0, 20)) . ".." . htmlspecialchars(substr($zeile, strlen($zeile) - 41, 40)) . "<br>"; fclose($z); $z = fopen($config['paths']['backup'] . $filedestination . '_part_' . $part . '.sql', "w"); $zeile = get_pseudo_statusline($part, $filedestination) . "\r\n"; gzwrite($z, $zeile); $zeile = ''; } } else { if ($cp == 1) { gzclose($z); $z = gzopen($config['paths']['backup'] . $filedestination . '_part_' . $part . '.sql.gz', "w"); $zeile = get_pseudo_statusline($part, $filedestination) . "\r\n" . $zeile; gzwrite($z, $zeile); } else { fclose($z); $z = fopen($config['paths']['backup'] . $filedestination . '_part_' . $part . '.sql', "w"); $zeile = get_pseudo_statusline($part, $filedestination) . "\r\n" . $zeile; fwrite($z, $zeile); } } $filesize = 0; $splitable = false; } else { $filesize += strlen($zeile); if ($n > 600) { $n = 0; echo '<br>'; } echo '.'; if ($cps == 1) { gzwrite($z, $zeile); } else { fwrite($z, $zeile); } flush(); } $n++; //if ($part>4) break; } $zeile = "\n-- EOB"; if ($cps == 1) { gzwrite($z, $zeile); gzclose($z); } else { fwrite($z, $zeile); fclose($z); } if ($cps == 1) { gzclose($f); } else { fclose($f); } echo '</span><h5>' . sprintf($lang['L_CONVERT_FINISHED'], $filedestination) . '</h5>'; }
function Converter($filesource, $filedestination, $cp) { global $config, $lang; $cps = substr(strtolower($filesource), -2) == "gz" ? 1 : 0; echo "<h5>" . sprintf($lang['convert_fileread'], $filesource) . ".....</h5><span style=\"font-size:10px;\">"; if (file_exists($config['paths']['backup'] . $filedestination)) { unlink($config['paths']['backup'] . $filedestination); } $f = $cps == 1 ? gzopen($config['paths']['backup'] . $filesource, "r") : fopen($config['paths']['backup'] . $filesource, "r"); $z = $cps == 1 ? gzopen($config['paths']['backup'] . $filedestination, "w") : fopen($config['paths']['backup'] . $filedestination, "w"); $insert = $mode = ""; $n = 0; $eof = $cps == 1 ? gzeof($f) : feof($f); while (!$eof) { $eof = $cps == 1 ? gzeof($f) : feof($f); $zeile = $cps == 1 ? gzgets($f, 8192) : fgets($f, 8192); if (substr($zeile, 0, 2) == "--") { $zeile = ""; } //$zeile=rtrim($zeile); $t = strtolower(substr($zeile, 0, 10)); if ($t > "") { switch ($t) { case "insert int": // eine neue Insert Anweisung beginnt $insert = substr($zeile, 0, strpos($zeile, "(")); if (substr(strtoupper($insert), -7) != "VALUES ") { $insert .= "VALUES "; } $mode = "insert"; break; case "create tab": $mode = "create"; while (substr(rtrim($zeile), -1) != ";") { $zeile .= fgets($f, 8192); } $zeile = "\n\r" . MySQL_Ticks($zeile) . "\n\r"; break; case "drop table": $mode = "drop"; $zeile .= "\n\r"; break; } if ($mode == "insert") { // Komma loeschen $zeile = str_replace("),(", ");\n{$insert} (", $zeile); if (substr(rtrim($zeile), 0, 2) == ",(" && $insert != "") { $zeile = ";\n" . $insert . substr($zeile, 1); } if (substr(rtrim($zeile), -2) == ")," && $insert != "") { $zeile = substr(rtrim($zeile), 0, strlen(rtrim($zeile)) - 1) . ";\n{$insert}"; } } $n++; if ($n > 1000) { $n = 0; echo "<br>"; } echo "."; if ($cps == 1) { gzwrite($z, $zeile); } else { fwrite($z, $zeile); } } flush(); $n++; } if ($cps == 1) { gzclose($z); } else { fclose($z); } if ($cps == 1) { gzclose($f); } else { fclose($f); } echo "</span><h5>" . sprintf($lang['convert_finished'], $filedestination) . "</h5>"; }