function restore_tables($file, $first_line = 0) { global $cfg; $iStart = time(); $iMET = 2; #(intval(ini_get('max_execution_time')) - 10); # We need some time for other tasks $db = new DB_Contenido(); $current_line = 0; # Open the backup file $gz = substr($file, -3) == '.gz'; $len = filesize($file); if ($gz) { if (!($handle = gzopen($file, 'r'))) { return false; } } else { if (!($handle = fopen($file, 'r'))) { return false; } } # Process the file line by line while (true) { while ($current_line < $first_line) { if ($gz) { $line = trim(gzgets($handle, $len)); } else { $line = trim(fgets($handle, $len)); } $current_line++; } if ($gz) { $line = trim(gzgets($handle, $len)); if (gzeof($handle)) { return true; } } else { $line = trim(fgets($handle, $len)); if (feof($handle)) { return true; } } $current_line++; if (strlen($line) && substr($line, 0, 2) != '--') { /* if ((substr(trim($line), 0, 10) == 'DROP TABLE') && ($current_line != ($first_line + 1))) { # New table definition $current_line --; return (int) $current_line; } */ while (substr(trim($line), -1) != ';') { if ($gz) { $line .= ' ' . trim(gzgets($handle, $len)); } else { $line .= ' ' . trim(fgets($handle, $len)); } $current_line++; } if (!$db->query($line)) { echo 'Error ' . $db->getErrorNumber() . ': ' . $db->getErrorMessage() . '<br />'; return false; } } # Time management if (time() - $iStart >= $iMET) { return (int) $current_line; } } return true; }