Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #11  
Old 17th May 2006, 01:02
RogueDogg RogueDogg is offline
Junior Member
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Red face

if someone could help me find or give me the code to do such a task I'd greatly appreciate it. All the ones I've found so far just don't do it.
Reply With Quote
Sponsored Links
  #12  
Old 17th May 2006, 15:29
falko falko is online now
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
  #13  
Old 11th June 2006, 09:03
EvanCarroll EvanCarroll is offline
Junior Member
 
Join Date: Jun 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by falko
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.
it is vulnerable to a sql-injection attack.
Reply With Quote
  #14  
Old 11th June 2006, 09:04
EvanCarroll EvanCarroll is offline
Junior Member
 
Join Date: Jun 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

All of these solutions are poor. I feel obliged to buzz in and suggest DBD::CSV.
Reply With Quote
  #15  
Old 11th June 2006, 12:52
falko falko is online now
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

I'm using this script in a password-protected area that only I can access...
__________________
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
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail System doesnt work! crichton Installation/Configuration 3 17th September 2007 23:49
Debian install error jf1976 Installation/Configuration 25 19th January 2006 22:31
ISP install problems Debian sarge 3.1 lerra Installation/Configuration 1 5th January 2006 16:37
PHP/MySQL/Apache2/ISPConfig configuration issues? senzapaura General 21 25th December 2005 14:01
/stats doesn't work (password not accepted) Hellbound General 6 15th September 2005 15:34


All times are GMT +2. The time now is 00:08.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.