我想循环浏览文件夹中的图像和缩略图,并将它们插入到数据库中。 我想用is_dir过滤掉目录。is_dir不适用于循环
我:
$images = scandir('./images/all_comics/');
$thumbs = scandir('./images/thumbnails/');
for($x=0; $x<count($images); $x++)
{
if(!is_dir($images[$x]))
{
//This shows all images WITHOUT directories
echo $images[$x];
//This is STILL adding images AND directories to database
mysql_query("INSERT INTO images (imgpath, thumbpath) VALUES ('$images[$x]', '$thumbs[$x]')");
}
}
我在那里有一个支票直接is_dir后,回声$图像[$ X],其回声的所有图像,而无需目录,按照需要!
但是,当我检查数据库中的插入,我看到目录已添加为记录。为什么是这样?
谢谢!
使用'glob' - '$图像=水珠( './图像/ all_comics/* JPG');',相应地更改格式。 – moonwave99