SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    orlando
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Gallery Script Issue

    Alright I found a gallery online that supports my needs written in php. (Code below) Now the idea is to the pull the images from a folder display pictures then pull text from a .txt file arranged as image.jpg,Caption For image, to then display a caption below. Currently it is only showing the first letter of the caption for that text file. Let me know if you see why it is not pulling the entire caption. I included the text file as an attachment and the php code is below. To view it in half working form: http://clarityassist.com/test/Lladrogallery/index.php

    Thanks in advance.

    <?php

    $images = "image_gallery/"; # Location of small versions
    $big = "big/"; # Location of big versions (assumed to be a subdir of above)
    $cols = 2; # Number of columns to display
    $text = "lladrogallery.txt";

    $fh=fopen($text, "r");

    while(!feof($fh))
    {
    $temp = explode(",", $line);
    $description[$temp[0]] = $temp[1];
    $line=fgets($fh);
    unset($temp);
    }

    if ($handle = opendir($images)) {
    while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != ".." && $file != rtrim($big,"/")) {
    $files[] = $file;
    }
    }
    closedir($handle);
    }

    $colCtr = 0;

    echo '<table width="100%" cellspacing="3"><tr>';

    foreach($files as $file)
    {
    if($colCtr %$cols == 0)
    echo '</tr><tr><td colspan="' . $cols . '"><hr /></td></tr><tr>';
    $allfiles .= $file . ',<br />';
    echo '<td align="center"><a href="' . $images . $big . $file . '"><img src="' . $images . $file . '" /></a><br />' . $description[$file][0] . '</td>';
    $colCtr++;
    }

    echo '</table>' . "\r\n";
    echo $allfiles;
    ?>
    Attached Files Attached Files

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Ljubljana, Slovenia
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in the echo line:
    PHP Code:
    $description[$file][0
    ?? the zero says first letter from string!

    PHP Code:
    $description[$file
    Gregor Grajzar, web developer
    http://xweblabs.com
    http://grajzar.info

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,268
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    The txt file looks a bit wrong
    Code:
    01001920.jpg,01001920 Arabian Pure Breed (Glazed)
    01001936.jpg,01001936 Iris and Cherry Flowers Fan
    01001939.jpg,01001939 Hina Dolls - Empress
    01001940.jpg,01001940 Hina Dolls - Emperor
    01007121.jpg,01007121 Lolita (Re-deco Platinum)
    01007122.jpg,01007122 Juanita (Re-dec Platinum)
    01007138.jpg,01007138 Chess Set (Re-Deco)
    01007813.jpg,01007813 My Little Sweetie Gift Box
    01007814.jpg,01007814 Beginnings Gift Box
    01008316.jpg,01008316 Mrigdangam Ganesha
    01008350.jpg,01008350 Alice in Wonderland
    01008351.jpg,01008351 Birds on Branch - Wall Art
    01008367.jpg,01008367 Chihuahua
    01008368.jpg,01008368 Maltese
    01008385.jpg,01008385 A Woman with Blue Eyes and Calla Lilly
    01008386.jpg,01008386 A Woman with a Hat and Calla Lilly
    01008396.jpg,01008396 Her Commencement
    01008397.jpg,01008397 His Commencement
    01008399.jpg,01008399 Summer Roses
    01008410.jpg,01008410 The Swan Princess
    01008411.jpg,Father Frost
    01008412.jpg,01008412 Snow Maiden
    01008417.jpg,01008417 Mahatma Gandhi
    01008422.jpg,01008422 Doves on a Cherry Tree
    01008423.jpg,01008423 ROCOCO Lady at the Ball
    01008424.jpg,01008424 ROCOCO Lady on Swing
    01008426.jpg,01008426 Tibetan Prayer Flags
    01008427.jpg,01008427 Blissful Youth
    01008428.jpg,01008428 Romantic Doves - Wall Art
    01008430.jpg,01008430 Soft Breeze
    01008432.jpg,01008432 Thothmes I Obelisk (Green)
    01008432a.jpg,01008432 Thothmes I Obelisk (Ochre)
    01008436.jpg,01008436 A Tender Caress
    01008438.jpg,01008438 Precious Angel
    01008439.jpg,01008439 Anubis
    01008440.jpg,01008440 Playing in the Sand
    01008441.jpg,01008441 Ancient Dynasty Warrior
    01008442.jpg,01008442 Sheep in the Meadow
    01008443.jpg,01008443 Ram in the Meadow
    01008444.jpg,01008444 Enchanted Prince
    01008445.jpg,01008445 Tree of Reflections
    01008446.jpg,01008446 Tree of Adventures
    01011920.jpg,01011920 Arabian Pure Breed (Matte)
    01040076.jpg,01040076 Spring Teddy Bear
    Anyway, if
    $temp = explode(",", $line);
    $description[$temp[0]] = $temp[1];
    then
    $description[01008411.jpg] = "Father Frost"
    but
    $description[01008411.jpg][0] = "F'

    As gregor171 said, lose the [0]

  4. #4
    SitePoint Member
    Join Date
    Sep 2004
    Location
    orlando
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    I appreciate the replys, of course losing the zero for the length of the string would fix the issue. Didn't even realize that was there, I guess I needed a fresh set of eyes. Thanks for your help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •