gpt4 book ai didi

php - 从多个文件夹中批量插入图像(文件夹中包含图像)将不起作用

转载 作者:行者123 更新时间:2023-11-29 10:45:36 25 4
gpt4 key购买 nike

大家好,我的 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 . "/";

正在复制img/部分。大概应该是

$path  = $dir . "/";

关于php - 从多个文件夹中批量插入图像(文件夹中包含图像)将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44635737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com