Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- function clean_all() {
- ob_start();
- $db = new mysqli ('localhost', '','', '');
- if (mysqli_connect_errno()) {
- exit (mysqli_connect_error());
- }
- $rez = $db->query('select table_name from information_schema.tables
- where table_schema=\'dmkim1_wp4\'
- ');
- if (!$rez)
- exit ($db->error);
- echo '<table><tr><td>';
- while ($row = $rez->fetch_field()) {
- echo '<td>'.$row->name.'</td>';
- //echo '<pre>'.print_r($row,true).'</pre>';
- }
- echo '</td></tr>';
- while ($row=$rez->fetch_array(MYSQLI_NUM)) {
- echo '<tr>';
- for ($i=0; $i<count($row); $i++) {
- echo '<td>'.$row[$i].'</td>';
- }
- if (!$db->query('delete from '.$row[0])) {
- echo '<td>'.$db->error.'</td>';
- }
- echo '</tr>';
- }
- echo '</table>';
- $rez->free();
- ob_end_clean();
- }
- function draw_info() {
- $infsql = $_SESSION["arrs"][$_SESSION["step"]];
- echo 'current step: '.$_SESSION["step"].'<br/><br/>';
- echo 'current sql: '.$infsql.'<br/>';
- }
- function proc_err() {
- $s =file_get_contents('errlog.html');
- echo '<div style="font-family:courier new, monospace;">'.$s.'</div>';
- }
- //-----------------------------------------------
- function proc_reqs() {
- $infsql = $_SESSION["arrs"][$_SESSION["step"]];
- $db = new mysqli('','','','');
- if (mysqli_connect_errno()) {
- exit (mysqli_connect_error());
- }
- if(!$db->query('SET NAMES utf8'))
- exit('wtf');
- function clr($el) {
- return substr(ltrim($el),0,2)!='--';
- }
- echo '<pre>'.print_r(array_filter(explode("\n", $infsql),'clr'),true).'</pre>';
- $infsql = implode (' ', array_filter(explode("\n", $infsql),'clr'));
- echo '<br/>'.strlen(trim($infsql)).'<br/>';
- if (strlen(trim($infsql))!=0) {
- if (!$db->query($infsql)) {
- $fz= fopen('errlog.html','a');
- fwrite($fz, $_SESSION["step"].'<br/><br>');
- fwrite($fz, $infsql.'<br/>'.$db->error);
- fwrite($fz, '<br/>'.str_repeat('-',100).'<br/><br/>');
- fclose($fz);
- }}
- $_SESSION["step"]++;
- //echo $_SERVER["REQUEST_URI"];
- $s = <<<INF
- <script type="text/javascript">
- window.onload = function() {
- setTimeout('location.replace(location.href);',500);
- }
- </script>
- INF;
- echo $s;
- //header('Location: '.$_SERVER["REQUEST_URI"].
- }
- //-----------------------------------------------
- function draw_pg() {
- $s = <<<INF
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <script type="text/javascript">
- window.onload = function() {
- wzz = window.open (location.protocol+'//'+location.hostname+location.pathname+location.search+'&proczz','wninf');
- izz = setInterval ( function() {
- frames["statusfr"].location.replace(location.href+'&infozz');
- frames["errfr"].location.replace(location.href+'&errzz');
- }, 1000);
- }
- </script>
- <iframe name="statusfr" width="800" height="500">
- </iframe>
- <iframe name="errfr" width="800" height="500">
- </iframe>
- INF;
- echo $s;
- }
- function check_z() {
- //echo '<pre>'.print_r($_SESSION, true).'</pre>';
- $arrs = $_SESSION["arrs"];
- //echo $arrs[0];
- if ((!isset($_GET["proczz"])) && (!isset($_GET["infozz"])) && (!isset($_GET["errzz"]))) {
- draw_pg();
- return;
- }
- if (isset($_GET["infozz"])) {
- draw_info();
- return;
- }
- if (isset($_GET["proczz"])) {
- proc_reqs();
- return;
- }
- if (isset($_GET["errzz"])) {
- proc_err();
- return;
- }
- }
- if (isset($_GET["gogo"])) {
- check_z();
- exit();
- }
- $logf = fopen('errlog.html','w');
- fclose($logf);
- clean_all();
- ob_start();
- define ('SQFILE','upl/k09.hostenko.com.sql');
- $s = file_get_contents(SQFILE);
- $arrs = explode(";\n",$s);
- $_SESSION["arrs"] = $arrs;
- $_SESSION["step"] = 0;
- session_commit();
- header('Location: '.$_SERVER["PHP_SELF"].'?gogo');
- ob_end_flush();
- exit();
- //------------------------ temp part for upload
- //---------------------------------
- function proc_uploaded() {
- $uplfile = $_FILES;
- echo '<pre>'.print_r($uplfile,true).'</pre>';
- if ($uplfile["fname"]["error"]===0) {
- if (!file_exists('upl')) {
- mkdir('upl');
- }
- move_uploaded_file($uplfile["fname"]["tmp_name"], 'upl/'.$uplfile["fname"]["name"]);
- } else {
- echo 'error uploading:'.$uplfile["fname"]["error"];
- }
- }
- if (!isset($_POST["submit"])) {
- $s = <<<INF
- <script type="text/javascript">
- window.onload = function() {
- var el = document.createElement('DIV');
- el.innerHTML = 'location '+location.href;
- document.body.appendChild(el);
- }
- </script>
- <form action="{$_SERVER["PHP_SELF"]}" method="post" enctype="multipart/form-data">
- <fieldset>
- <legend>Upload sql file</legend>
- <label for="fname">Choose file</label><input type="file" name="fname" />
- <p><input type="submit" name="submit" value="upload" /></p>
- </fieldset>
- </form>
- INF;
- echo $s;
- } else {
- proc_uploaded();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement