I have about 400 files that contains logs from various IRC channels. I don't think it's worth the time to insert them one by one into the database, so I'm trying to create a script that does this.
Anyway, i did #ls > logs.txt so I got all filenames into one file.
and then I did this script
<?
//open the file
$fcontents = file ('logs.txt');
while (list ($line_num, $line) = each ($fcontents)) {
$filename = "$line";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
$login="xxxxx";
$pass="xxxxx";
$db=mysql_connect("localhost",$login,$pass);
mysql_select_db("Loggarna",$db);
$sql= "insert into Logs (Name, Content) values ('$filename','$contents')";
$result=mysql_query($sql,$db);
fclose ($fd);
}
?>
But it doesn't work, I keep getting errors like:
Warning: fopen("#askersund_20010305.log ","r") - No such file or directory in
/c/www/server/loggarna/monge.php on line 7
and
Warning: Supplied argument is not a valid File-Handle resource in
/c/www/server/loggarna/monge.php on line 8
What am I doing wrong here?
or does anyone know of a better way?
Anyway, i did #ls > logs.txt so I got all filenames into one file.
and then I did this script
<?
//open the file
$fcontents = file ('logs.txt');
while (list ($line_num, $line) = each ($fcontents)) {
$filename = "$line";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
$login="xxxxx";
$pass="xxxxx";
$db=mysql_connect("localhost",$login,$pass);
mysql_select_db("Loggarna",$db);
$sql= "insert into Logs (Name, Content) values ('$filename','$contents')";
$result=mysql_query($sql,$db);
fclose ($fd);
}
?>
But it doesn't work, I keep getting errors like:
Warning: fopen("#askersund_20010305.log ","r") - No such file or directory in
/c/www/server/loggarna/monge.php on line 7
and
Warning: Supplied argument is not a valid File-Handle resource in
/c/www/server/loggarna/monge.php on line 8
What am I doing wrong here?
or does anyone know of a better way?