【发布时间】:2017-06-19 16:36:08
【问题描述】:
大家好,我的 mysql 批量图像插入脚本无法正常工作。我不知道为什么。 我在根目录中有上传脚本,在这个文件夹中有一个名为 img 的文件夹中的图像,一个按类别命名的文件夹,其中包含图像,因此插入到 mysql 中。但他每次都说我“没有匹配的文件插入到数据库中。 "我不知道为什么路径应该没问题。
这里是脚本家伙
$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.";
}
}
}
?>
【问题讨论】:
-
你试过相对路径吗?
$path = "./img/" . $dir . "/"; -
@SloanThrasher 是的,试过了,不行
-
@SloanThrasher 还有其他想法吗?
-
@SloanThrasher 他说他没有要插入的文件。所以我认为他找不到类别文件夹。
-
你有没有试过
echo $path;在你第一次构建它之后,看看你得到了什么价值。
标签: php mysql bulkinsert directory bulk