Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $host = 'localhost';
- $username = 'root';
- $password = '';
- $database = 'peter';
- $db = new mysqli('localhost','root','','tst');
- include('../../repair/php/fungsi.php');
- if(!isset($_SESSION['upload'])){
- echo 'File was not uploaded!';
- exit;
- }
- if(!isset($_SESSION['import_num'])){
- if(file_exists('db')) recursiveDelete('db');
- // if(file_exists('db.zip')) unlink('db.zip');
- if(file_exists('db.zip')){
- $archive = 'db.zip';
- $zip = new ZipArchive;
- $extracted = 'db';
- $open = $zip->open($archive);
- if($open === true){
- $zip->extractTo($extracted);
- $zip->close();
- unlink($archive);
- }
- }
- if(file_exists('db')){
- $a = $db->query("select database() s") or die($db->error);
- $ad = $a->fetch_assoc();
- $mydatabase = $ad['s'];
- // drop
- $q1 = $db->query("show tables") or die($db->error);
- while($qd = $q1->fetch_assoc()){
- $table = $qd['Tables_in_'.$mydatabase];
- $drop = $db->query("drop table `$table`") or die($db->error);
- }
- $links = array();
- foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator('db/', FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path){
- if($path->isFile()){
- $links[] = $path;
- }
- }
- $_SESSION['import_num'] = count($links);
- $_SESSION['db_files'] = $links;
- $sql = file_get_contents('db/tables.sql');
- flush_multi_query($sql);
- unlink('db/tables.sql');
- $spos = array_search('db/tables.sql',$_SESSION['db_files']);
- unset($_SESSION['db_files'][$spos]);
- $rf = count($_SESSION['db_files']);
- $ja = '[{"status":"next set of records!","files":"'. $rf .'","num":"'. $_SESSION['import_num'] .'"}]';
- echo $ja;
- }
- }
- else{
- /*$status = "";
- $rf = count($_SESSION['db_files']);
- $fl = $_SESSION['db_files'][0];
- $content = file_get_contents($fl);
- $ar = explode('/',$fl);
- $ls = $ar[count($ar) - 1];
- $a2 = explode('.',$ar);
- if(!isset($a2[1])){
- $status = "An error occured!";
- }
- else{
- $table = $ar[count($ar) - 2];
- $d = $db->query("show columns from `$table`") or die($db->error);
- $counter = 0;
- $cols = '';
- $update = '';
- while($dd = $d->fetch_assoc()){
- if($counter == 0){
- $cols = '`'.$dd['Field'].'`';
- $update = '`'.$dd['Field'].'` = values(`'.$dd['Field'].'`)';
- }
- else{
- $update = ',`'.$dd['Field'].'` = values(`'.$dd['Field'].'`)';
- $cols = ', `'.$dd['Field'].'`';
- }
- $counter++;
- }
- // $columns = '('.$cols.')';
- $sql = "insert into `$table` ($cols) ".$content." on duplicate key update $update";
- flush_multi_query($sql);
- $status = "next set of records!";
- $spos = array_search($fl,$_SESSION['db_files']);
- unset($_SESSION['db_files'][$spos]);
- unlink($fl);
- }
- $rf = count($_SESSION['db_files']);
- if($rf == 0) $status = "successfully imported!";
- $ja = '[{"status":"'.$status.'","files":"'. $rf .'","num":"'. $_SESSION['import_num'] .'"}]';*/
- echo 'abc';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement