import.php
上传用户:jiangbw
上传日期:2022-03-16
资源大小:49k
文件大小:6k
- <?
- /*======================================================================*
- || #################################################################### ||
- || # BUILD UNDER PHP SCRIPTNET 3.2.1 FRAMEWORK ||
- || # ---------------------------------------------------------------- # ||
- || # Code2Art Open Source Software. All Rights Reserved. ||
- || # This file should be redistributed in whole or significant part. # ||
- || # ------------------ SCRIPTNET IS FREE SOFTWARE ------------------ # ||
- || # http://www.code2art.com | http://www.code2art.com/scriptnet # ||
- || # Copyleft by Benediktus Ardian Hersanto, SE # ||
- || # Sorry if this framework is still unavailable for public # ||
- || # because I still searching on my own head. # ||
- || #################################################################### ||
- *======================================================================*/
- /*======================================================================*
- || #################################################################### ||
- || DBF to MySQL Bulk Converter 2.0 ||
- ||______________________________________________________________________||
- || This utility was developed on 2006, since this were used to be on ||
- || my own library. But I think I should share it to you, because I ||
- || need to save my work on Internet (I don't believe on my own HD drive)||
- || it always crash and had a terrible bad sectors. ||
- || Thanks to all person who download this utility, I hope you enjoy it. ||
- || ||
- || Regards, ||
- || Benediktus Ardian Hersanto,SE (ardie_b@yahoo.com) ||
- /*======================================================================*/
- // ---------------------------------------------------------------------//
- // Free to use for everyone who understand PHP
- // ---------------------------------------------------------------------//
- include('init.php');
- LoadClass('session');
- LoadLibrary('dbms');
- $session = new session;
- if(!isset($_POST['dbname'])) {
- if(isset($_SESSION['source'])) {
- $post = unserialize($_SESSION['source']);
- define('DB_NAME',$post['dbname']);
- }
- } else {
- define('DB_NAME',$_POST['dbname']);
- }
- set_time_limit(0);
- LoadClass("dbf");
- if(!isset($_SESSION['source'])) {
- $keys = array_keys($_POST);
- $total_table = 0;
- for($i=0;$i<count($keys);$i++) {
- if (eregi(".dbf",$_POST[$keys[$i]])) {
- $dbfs = explode(",",$_POST[$keys[$i]]);
- $total_table += count($dbfs);
- }
- }
- $_POST['total_table'] = $total_table;
- $_POST['counter'] = 1;
- $source = serialize($_POST);
- $session->register('source');
-
- $dbfs = explode(",",$_POST[$keys[0]]);
- if(eregi('.dbf',$_POST[$keys[0]])) {
- $n = 0;
- $dbffile = DEFAULT_DATA_DIR."/".$keys[0]."/".$dbfs[$n];
- $dbf = new dbf($dbffile);
- $dbf->parseFile();
- $SQL = $dbf->createMySQLTable();
- if(!empty($SQL)) {
- $d = new DBMS;
- $db->Trace(__LINE__); $db->Query($SQL);
- $data = $dbf->parseData();
- $file = basename($dbfs[$n]);
- $table_name = eregi_replace(".dbf",'',$file);
- if((count($data)>0)&&($data!=NULL)) {
- for($i=0;$i<count($data);$i++) {
- $fields = array_keys($data[$i]);
- for($f=1;$f<count($fields);$f++) {
- if($data[$i][$fields[0]]!='*') {
- if(is_string($data[$i][$fields[$f]])) {
- $field[] = $fields[$f];
- $records[] = "'".addslashes(trim($data[$i][$fields[$f]]))."'";
- } else if(is_array($data[$i][$fields[$f]])) {
- $field[] = $fields[$f];
- $tgl = $data[$i][$fields[$f]]['Year'].$data[$i][$fields[$f]]['Month'].$data[$i][$fields[$f]]['Day'];
- if(trim($tgl)=='') $records[] = "null"; else
- $records[] = "'".$tgl."'";
- }
- }
- }
- if(!$db->Insert($table_name,implode(",",$field),implode(",",$records))) die(mysql_error());
- unset($field);
- unset($records);
- }
- }
- }
- echo "<meta http-equiv='refresh' content='0;url=import.php?id=".$keys[0]."&idx=".($n+1)."'>";
- $procentage = 1/$total_table;
- include('progress_bar.htm');
- }
- } else {
- $keys = array_keys($post);
- if(isset($post[$_GET['id']])) $dbfs = explode(",",$post[$_GET['id']]);
- $n = $_GET['idx'];
- if(!isset($dbfs[$n])) {
- array_shift($post);
- $n = 0;
- $keys = array_keys($post);
- $dbfs = explode(",",$post[$keys[0]]);
- }
- if(isset($dbfs[$n])) {
- $post['counter'] += 1;
- $source = serialize($post);
- $session->register('source');
- $dbffile = DEFAULT_DATA_DIR."/".$keys[0]."/".$dbfs[$n];
- if(file_exists($dbffile)) {
- $dbf = new dbf($dbffile);
- $dbf->parseFile();
- $SQL = $dbf->createMySQLTable();
- if(!empty($SQL)) {
- new DBMS;
- $db->Trace(__LINE__); $db->Query($SQL);
- $data = $dbf->parseData();
- $file = basename($dbfs[$n]);
- $table_name = eregi_replace(".dbf",'',$file);
- if(eregi('clear',$post['type'])) $db->Query('TRUNCATE '.$table_name);
- if((count($data)>0)&&($data!=NULL)) {
- for($i=0;$i<count($data);$i++) {
- $fields = array_keys($data[$i]);
- for($f=1;$f<count($fields);$f++) {
- if($data[$i][$fields[0]]!='*') {
- if(is_string($data[$i][$fields[$f]])) {
- $field[] = $fields[$f];
- $records[] = "'".addslashes(trim($data[$i][$fields[$f]]))."'";
- } else if(is_array($data[$i][$fields[$f]])) {
- $field[] = $fields[$f];
- $tgl = $data[$i][$fields[$f]]['Year'].$data[$i][$fields[$f]]['Month'].$data[$i][$fields[$f]]['Day'];
- if(trim($tgl)=='') $records[] = "null"; else
- $records[] = "'".$tgl."'";
- }
- }
- }
- if(!$db->Insert($table_name,implode(",",$field),implode(",",$records))) die(mysql_error());
- unset($field);
- unset($records);
- }
- }
- }
- echo "<meta http-equiv='refresh' content='0;url=import.php?id=".$keys[0]."&idx=".($n+1)."'>";
- $procentage = $post['counter']/$post['total_table'];
- include('progress_bar.htm');
- } else {
- $session->destroy();
- echo "<script> alert('Tables was successfully imported'); location.href='".(ereg('http://',DOMAIN_NAME)?DOMAIN_NAME:'http://'.DOMAIN_NAME)."';</script>";
- }
- }
- }
- ?>