image gallery

I am new to php and am trying to create an image gallery with captions being pulled for a text file. The images are in a directory. The images load fine but the captions only show the first letter of each under the image???
Here’ my code:

<?php $images = "./images/"; # 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 = "image_gallery_descriptions.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 ''; foreach($files as $file) { if($colCtr %$cols == 0) echo ''; $allfiles .= $file . ',
'; echo ''; $colCtr++; } echo '


' . $description[$file][0] . '
' . "rn"; ?>

Your help is appreicated.

$description[$file][0] <-- is your problem. Your text in $description[$file] is a string, which can be accessed character-by-character if you treat it as an array. Use $description[$file] instead and see if that solves your issue.

Sponsor our Newsletter | Privacy Policy | Terms of Service