I am writing a script that reads through a bunch of html files in several directories and inserts the html and all content into a MySQL database. Weird thing is that when it runs through the files and inserts it always misses some files. I checked them and they are the same type of html files and same naming convention. I'm stumped. The files seem to be fine and should be readable. Does anybody have any ideas or have run into this? Any help is greatly appreciated.
Thanks!
Dino
<?
function listdir($base) {
static $filelist = array();
$dh = opendir($base);
while ($dir = readdir($dh)) {
$subbase = $base ."/". $dir;
if(is_dir($subbase) && $dir !== '.' && $dir !== '..') {
listdir($subbase);
}
elseif(is_file($subbase) && $dir !== '.' && $dir !== '..') {
$filelist[] = $subbase;
}
}
closedir($dh);
return $filelist;
}
$host = "localhost";
$username = "root";
$password = "red";
$allthefiles = listdir('/web/help/interface');
for($i=0;$i<sizeof($allthefiles);$i++)
{
$fullfilepath = $allthefiles[$i];
if (is_readable($fullfilepath))
{
$file = fopen($fullfilepath, "r");
$contents = fread($file, filesize($fullfilepath));
fclose($file);
//print $contents;
$connection = mysql_connect($host,$username,$password);
if ($connection == false){
echo mysql_errno().": ".mysql_error()."<BR>";
echo("You gotta problem dude!!");
exit;
}
mysql_select_db("helpdatatest");
mysql_query ("INSERT INTO help VALUES ('$fullfilepath', '$contents', '', '', '', '')");
}
}
?>