View Single Post
  #12  
Old 17th May 2006, 15:29
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,735 Times in 2,571 Posts
Default

This is a small snippet of a PHP script that I wrote:

PHP Code:
    $columns $app->db->queryAllRecords("SHOW COLUMNS FROM ".$_POST['table']);
    
$columns array_slice($columns1);
    
$app->db->query("TRUNCATE ".$_POST['table']);
    
$app->uses('file');
    
$content file_get_contents($_FILES['file']['tmp_name']);
    
$lines explode("\n"$content);
    foreach(
$lines as $line){
      
$fields explode("\""$line);
      
$sql "INSERT INTO ".$_POST['table']."(";
      
$sql1 $sql2 '';
      
$l 0;
      for(
$i=0;$i<sizeof($fields);$i++){
        
$k 0;
        if(
substr($fields[$i],0,1) == '"' && substr($fields[$i],-1) != '"'){
          
$j $i 1;
          do {
            
$fields[$i] .= $fields[$j];
            
$j++;
            
$k++;
          } while(
substr($fields[$j-1],-1) != '"');
        }
        if(
substr($fields[$i],0,1) == '"' && substr($fields[$i],-1) == '"'$fields[$i] = substr($fields[$i],1,-1);

        
$fields[$i] = str_replace('""''"'$fields[$i]);
        
$sql1 .= $columns[$l]['Field'];
        
$l++;
        
$sql2 .= "'".addslashes($fields[$i])."'";
        if(
$i < (sizeof($fields)-1)){
          
$sql1 .= ',';
          
$sql2 .= ',';
        }
        
$i += $k;
      }
      
$sql .= $sql1.") VALUES (".$sql2.");";
      
//echo $sql."<br>";
      
$app->db->query($sql);
    } 
It should give you the idea.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote