Gazz1982 Posted June 7, 2008 Share Posted June 7, 2008 I have this code which makes a 2 column table with images from a folder, it gets the captions from a text file - see below <?php $images = "uploads/"; # Location of small versions $big = "thumbs/"; # Location of big versions (assumed to be a subdir of above) $cols = 2; # Number of columns to display $text = "des.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 width="300px" src="' . $images . $file . '" /></a><br />' . $description[$file][0] . '</td>'; $colCtr++; } echo '</table>' . "\r\n"; echo $allfiles; ?> this file des.txt has file_name,caption however when implemented it only seems to display the 1st letter of the caption - any ideas why and how to solve? Thanks scan0006.jpg,Pic1 scan0005.jpg,scan0005.jpg scan0003.jpg, scan0009.jpg, scan0002.jpg, scan0008.jpg, scan0001.jpg, scan0004.jpg, scan0007.jpg, Quote Link to comment https://forums.phpfreaks.com/topic/109187-adding-cations-to-images/ Share on other sites More sharing options...
hansford Posted June 7, 2008 Share Posted June 7, 2008 in this piece of your code I don't understand what is getting exploded. $line doesn't get defined until after explode(). Please explain while(!feof($fh)) { $temp = explode(",", $line); $description[$temp[0]] = $temp[1]; $line=fgets($fh); unset($temp); } Quote Link to comment https://forums.phpfreaks.com/topic/109187-adding-cations-to-images/#findComment-560104 Share on other sites More sharing options...
Gazz1982 Posted June 7, 2008 Author Share Posted June 7, 2008 OK NOW SET AS: while(!feof($fh)) { $line=fgets($fh); $temp = explode(",", $line); $description[$temp[0]] = $temp[1]; unset($temp); } Quote Link to comment https://forums.phpfreaks.com/topic/109187-adding-cations-to-images/#findComment-560114 Share on other sites More sharing options...
hansford Posted June 7, 2008 Share Posted June 7, 2008 ok great. now we have the $description array I don't know how you want to iterate through it but if its consecutive we can just grab the first key and then move the pointer to the second and so on foreach($files as $file) { if($colCtr %$cols == 0) $descript = current($description); echo '</tr><tr><td colspan="' . $cols . '"><hr /></td></tr><tr>'; $allfiles .= $file . ',<br />'; echo '<td align="center"><a href="' . $images . $big . $file . '"><img width="300px" src="' . $images . $file . '" /></a><br />' . $descript . '</td>'; $colCtr++; next($description); } Quote Link to comment https://forums.phpfreaks.com/topic/109187-adding-cations-to-images/#findComment-560123 Share on other sites More sharing options...
Gazz1982 Posted June 8, 2008 Author Share Posted June 8, 2008 Thank you - perfect Quote Link to comment https://forums.phpfreaks.com/topic/109187-adding-cations-to-images/#findComment-560359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.