Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

 
 
Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
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
 


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 03:45 AM.


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