1

I'm trying to think of a way to make this happen.

I'm using a jQuery slideshow to display images, and a simple php script to pull the images from a folder based on which gallery the user selects:

    $handle = opendir(dirname(realpath(__FILE__)).'/../images/gallery/'.$gallery);
while($file = readdir($handle)){
    if($file !== '.' && $file !== '..'){
        $pictures .= '<img src="images/gallery/'.$gallery.'/'.$file.'" alt="" />';
    }
}

I'm doing it this way since there are 6 different galleries, and the amount of photos in each gallery varies, from about 25 - 40 pictures. If I did the site staticly, or had a database running it'd be no problem, but I can't think of a PHP way of doing this.

Basically here is an example of what I'm hoping to do: I hard coded all the images and text

But on this page I can't think of a good way of doing it

4

2 回答 2

2

info.txt您可以像描述一样添加到每个文件夹文件。在加载时检查 file_exists() 并从文件中获取数据。

如果你想为每张照片设置 desc,你可以这样做:

对于文件:

  • 花.jpg
  • 云.jpg
  • 女孩.jpg

信息.txt:

flower.jpg::This is flower
cloud.jpg::This is cloud
girl.jpg::This is girl

因此,您阅读 info.txt,按行分解并最后分解行。结果,您将获得带有描述和文件名的数组。

于 2013-02-05T15:38:17.033 回答
-1

可能不是最好的方法,但这是我完成它的解决方法:`我将图像重命名:01-A Bird,02-A Cat

$handle = opendir(dirname(realpath(__FILE__)).'/../images/gallery/'.$gallery);
while($file = readdir($handle)){
    if($file !== '.' && $file !== '..'){

        $alt = substr($file, 3, -4); //Removes the "##-" and the ".jpg"
        $id = substr($file, 0, 2); // Removes EVERYTHING after the "##"

    // The image
        $pictures .= '<img src="images/gallery/'.$gallery.'/'.$file.'" alt="'.$alt.'" data-caption="#cap'.$id.'" />';
    // The text
        $span .= '<span class="caption" id="cap'.$id.'">'.$alt.'</span>';

    }
}`
于 2013-02-05T19:51:24.383 回答