if (is_dir($dir)) {
if($handle = opendir($dir)) {
while($file = readdir($handle)) {
// Break the filename by period; if there's more than one piece, grab the last piece.
$parts = explode(".", $file);
if (is_array($parts) && count($parts) > 1) {
$ext = end($parts);
// If it's an image that we want, echo the code.
if ($ext == "png" OR $ext == "PNG" OR $ext == "jpg" OR $ext == "JPG" OR $ext == "jpeg" OR $ext == "JPEG" OR $ext == "gif" OR $ext == "GIF")
echo "<img src=\"$path/$file\" />";
}
}
closedir($handle);
}
...
我在 Wordpress 中使用它,页面加载速度很慢,但也可能是因为上面有很多图像。我只是想确保我没有做一些因性能原因而令人不悦的事情。