I3arry
01-23-2007, 02:11 PM
I use this script to read a text file and add it to a database.
<?php
include ("config.php");
if ( !$iplistTXT = file_get_contents ( "iplist.txt" ) )
{
echo"Error, file is empty";
}
else
{
$ipArray = explode( "\n", $iplistTXT);
$arraysize = sizeof($ipArray) -1;
for ( $i = 0; $i < $arraysize; $i++)
{
$ipArray[$i] = explode ( "\t", $ipArray[$i] );
$name = str_replace ( "'", "\'", trim($ipArray[$i][0]) );
$ip = trim($ipArray[$i][1]);
mysql_query("INSERT IGNORE INTO ipinfo(name,ip) VALUES('".$name."','".$ip."')") or die(mysql_error());
}
}
?>
I'd like to be able to have it read text files with other names that are located in other folders.
Such as:
root dir
folder1
iplista.txt
iplistb.txt
folder2
iplist1.txt
iplist2.txt
<?php
include ("config.php");
if ( !$iplistTXT = file_get_contents ( "iplist.txt" ) )
{
echo"Error, file is empty";
}
else
{
$ipArray = explode( "\n", $iplistTXT);
$arraysize = sizeof($ipArray) -1;
for ( $i = 0; $i < $arraysize; $i++)
{
$ipArray[$i] = explode ( "\t", $ipArray[$i] );
$name = str_replace ( "'", "\'", trim($ipArray[$i][0]) );
$ip = trim($ipArray[$i][1]);
mysql_query("INSERT IGNORE INTO ipinfo(name,ip) VALUES('".$name."','".$ip."')") or die(mysql_error());
}
}
?>
I'd like to be able to have it read text files with other names that are located in other folders.
Such as:
root dir
folder1
iplista.txt
iplistb.txt
folder2
iplist1.txt
iplist2.txt