hi Guys my bulk image insert script for mysql isnt working.i cant figure out why. I have the upload Script in root directory and the images in a folder called img in this folder a folders named by category with images in it so insert into mysql.but he says me everytime "There were no matching files to insert into the database." dont know why paths should be okay i think.
Here is the script guys
$connect = mysql_connect($server,$dbuser,$dbpass);
mysql_select_db($dbname,$connect);
$dirs = array_filter(glob('img/*'), 'is_dir');
foreach ($dirs as $dir) {
$path = "img/" . $dir . "/";
$files = array_map('mysql_real_escape_string', array_filter(glob("{$path}*.*"), 'is_file'));
if (empty($files)) {
echo "There were no matching files to insert into the database.";
} else {
$insertValues = array();
foreach ($files as $file) {
$data = getimagesize($file);
$width = $data[0];
$height = $data[1];
$insertValues[] = "('Titel', {$dir}, '{$file}', '$width', '$height')";
}
$query = "INSERT INTO `gbpics` (`gbpictitel`, `gbpiccat`, `gbpicurl`, `gbpicwidth`, `gbpicheight`) VALUES " . implode(', ', $insertValues);
if (!mysql_query($query)) {
echo "There was a problem inserting the data.";
trigger_error("Query failed: $query<br />Error: " . mysql_error());
} else {
echo "The data was inserted successfully.";
}
}
}
?>
I think
$path = "img/" . $dir . "/";
is duplicating the img/ part. Probably should be
$path = $dir . "/";