我正在实现一个脚本,它将图像添加到文件夹中的页面。是,我发现了错误如下:使用php从文件夹添加图像,需要使用正确的正则表达式函数
警告:排序()预计参数1是阵列,在C空给出:\ XAMPP \ htdocs中\ mysite的\上线25
和
design.php警告:在C的foreach()提供参数无效:\ XAMPP \ htdocs中\ mysite的上线路26
\ design.php使用EREG原始脚本,这是我然后用的preg_match取代,但仍然存在问题,有一天我会知道所有这些函数实际上都返回了。
在此先感谢。我有感觉有重复,但我还没有找到它。
$dir = "../mysite/images/";
$dh = opendir($dir);
while($filename = readdir($dh))
{
$filepath = $dir.$filename;
//pregmatch used to be ereg. which function is best?
if (is_file($filepath) and preg_match("\.png$",$filename))
{
$gallery[] = $filepath;
}
}
sort($gallery);
foreach($gallery as $image)
{
echo "<hr>";
echo"<img src='$image'><br>";
}
+1,为什么推倒重来。 – codaddict
不错的一个。我从来没有遇到过这个功能。好好学习它存在。 –
这有什么不同? – expiredninja