Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2005-09-02, 01:04 PM   #1
Useless
Certified Nice Person
 
Useless's Avatar
 
Join Date: Oct 2003
Location: Dirty Undies, NY
Posts: 11,268
Send a message via ICQ to Useless
I Need a Batch Import Script

As the title states, I'm looking for a batch import script (hopefully PHP) that I could modify and super glue into my link list script. I want to be able to add pipe delimited text into my database, as such:
Site 1 Title | URL | description | other shit
Site 2 Title | URL | description | other shit
Site 3 Title | URL | description | other shit
Site 4 Title | URL | description | other shit

I just checked my budget and I see that the script must cost somewhere between $00.00 and $3.95.
__________________
Click here to purchase a bridge I'm selling.
Useless is offline   Reply With Quote
Old 2005-09-02, 02:01 PM   #2
Halfdeck
You can now put whatever you want in this space :)
 
Halfdeck's Avatar
 
Join Date: Oct 2004
Location: New Haven, CT
Posts: 985
Send a message via ICQ to Halfdeck
This is the code I use for batch importing. It takes a .txt file, parses it and inserts info into my MYSQL DB.

It needs to be rewritten (I just ripped it off one of my scripts), it'll create undeletable files on your server depending on server setting, its a bit clunky 'cause it doesn't use regexp... and you need an HTML with a form that takes files with BROWSE, but I'm about to hit the sack .. so I'll just post it.

PHP Code:
$batchlinksdir "mysql/batchfiles"// directory where the .txt file's uploaded.

upload_file("batchlinks"$batchlinksdir);
    
$batchfilename $_FILES['batchlinks']['name'];
    
    
$file fopen("../batch/$batchfilename""r");
    while(
$fileline fscanf($file"%[a-zA-Z0-9@&=;_:./ '!?-]\n")) {
        
        list(
$myline) = $fileline;
        
        
$myline substr($mylinestrpos($myline"http:"), strlen($myline));
        
        list(
$url) = sscanf($myline"http://%[a-zA-Z0-9@&=_,:./!?-][ |\n]");
        
        if(
$url=='') echo "EMPTY STRING<BR>";
        else {
            
$url "http://" .$url;
            echo 
"PARSED URL: " .$url ."<BR>";
            
/*_ First, check if the url already's in the database __*/
        
              
$query "SELECT * FROM hosted_gallery WHERE url=\"$url\"";
              
$result mysql_query($query) or mysql_error();
              if(
mysql_num_rows($result)>0) echo "URL: [$url]::DUPLICATE ENTRY<BR>";
              else {
          
                  
$query "INSERT INTO hosted_gallery (url,site_id,description,title, url_type_id, static,content_type,niche_id,disable, thumb, date_added,dvd_id) VALUES ('$url','$site_id',\"$description\",\"$title\", '$url_type_id', '$static','$content_type','$niche_id', '$disable', '$thumbname', '$date_added', '$dvd_id')";
                  
$result mysql_query($query) or error_msg($query ." modify-gallery.php::batch<BR>");
              }
        }
    }
    
fclose($file);
     exit;

__________________
Success is going from failure to failure without a loss of enthusiasm.
Halfdeck is offline   Reply With Quote
Old 2005-09-03, 09:11 AM   #3
rich06
Internet! Is that thing still around?
 
Join Date: Oct 2004
Location: French Riviera
Posts: 7
Send a message via ICQ to rich06
Here's around er... $2.15 worth of PHP code that should get you started...

PHP Code:
<?
$sites 
file('/path/to/my/text/file.txt');

if (
is_array($sites)) {
    foreach (
$sites as $site) {
        
$bits explode('|',$site);
        
$sql 'insert into mytable (title,url,description,other_shit) ';
        if (
is_array($bits)) {
              
mysql_query($sql."('{$bits[0]}','{$bits[1]}','{$bits[2]}','{$bits[3]}')") or die('whatever');
         }
      }
}
?>
hth
rich
__________________
ICQ# 6820996
rich06 is offline   Reply With Quote
Old 2005-09-03, 12:05 PM   #4
Useless
Certified Nice Person
 
Useless's Avatar
 
Join Date: Oct 2003
Location: Dirty Undies, NY
Posts: 11,268
Send a message via ICQ to Useless
I knew I should of up'd my budget to the full 5 bucks.

Thanks guys.
__________________
Click here to purchase a bridge I'm selling.
Useless is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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


All times are GMT -4. The time now is 04:06 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc