0

I'm trying to use PHP to bring in every image from a specific directory and turn them into HTML objects by wrapping some markup around them.

Right now I am just trying to get the images on the page. In the future I would also like to bring in a text file that has the same file name as the image(slide#4.jpg and slide#4.txt).

This is what I have so far.

<?php

    $dir = "includes/pages/products/*.jpg";

    $images = glob( $dir );

    foreach( $images as $image ):
        $file = basename($image);
        $file = basename($image, ".jpg");
        echo "<div class='"prod-cont"'>" . "<h4>" . $file . "</h4>" . "<img src'" . $image "' />" . "</div>";
    endforeach;
?>

I'm not having much luck getting this going, any help is appreciated.

4

1 回答 1

1

Remove the second $file = line, and make sure you're generating correct HTML.

echo "<div class='prod-cont'><h4>".$file."</h4><img src='".$image."' /></div>";
于 2013-02-10T23:27:03.237 回答