-1

这可能是一个非常简单的解决方案,但我是 PHP 新手,我一直在搜索谷歌以了解如何让它工作但无济于事。这是我的问题,我希望能够使用该glob功能extract(pathinfo)来查找文件夹中的所有图像并将它们打印到 html 页面中。我只能将一张图像打印到屏幕上,我认为它会打印它们以便找到文件。这是我的代码:

<?php 
$images = glob('*.{png,jpg,jpeg}', GLOB_BRACE);

foreach($images as $img) {
    extract(pathinfo($img));
    $thumb_name = "$filename.$extension";       
    //$thumb_name = $info['filename'] . '.' . $info['extension'];
    echo $thumb_name . "\n";
}
?>

最后是 html 文件:

<?php include 'index.php' ?>
<html>
<head>
<title>Insert title here</title>
</head>
<body>

<?php echo "<img src=\"$thumb_name\" title=\"bar\" alt=\"foo\" />"; ?>
<?php echo "<img src=\"$thumb_name\" title=\"bar\" alt=\"foo\" />"; ?>


</body>
</html>
4

1 回答 1

0

不是实际的工作代码,只是为了让你有个想法

将 echo img 放入 for 循环中

     $images = glob('*.{png,jpg,jpeg}', GLOB_BRACE);
     foreach($images as $img){
        extract(pathinfo($img))
      $thumb_name = "$filename.$extension";       
      echo     '<img src=\'.$thumb_name\.' title=\bar\ alt=\foo\ />';
           }
于 2012-10-21T06:31:55.727 回答