Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

my PHP gallery script not working

Posted on 2006-11-25
9
Medium Priority
?
265 Views
Last Modified: 2008-03-03
Experts,

I am attempting to create a thumnail gallery for one of my websites.  I need the script to show five images per row, however this is not working currently, please help;

<?
// Paths to images
$thumbs = "thumbs";
$images = '/PHPgallery/images/';

// Image sizes
$height = "70px";
$xsize = "55px";


// Count number of files in folder

$d = dir("thumbs");
$numoffiles=0;
while($entry=$d->read()) {
      if (($entry<>'.') and ($entry<>'..')) $numoffiles++;
       }

$d->close();
 
// Thumbnail generator
if($dir = opendir($thumbs)){
echo "<table border=\"1\" cellspacing=\"5\">\n";
echo "<tr>\n";
$n = 0;
      for($x = 0; $file = readdir($dir); $x++) {
    $shorten = strtolower(substr($file, -3));
          if($shorten == "jpg" || $shorten == "gif" || $shorten == "png") {                    
        $path = "$thumbs"."/"."$file";
        $files[$n] = $path;    
        echo "<td width=\"80\" height=\"65\"><img src=\"$files[$n]\" height=\"$height\" width=\"$xsize=\"></td>"."\n";
        $n++;
            if($n % 5 == 0) echo '</tr><tr>';
            }
            echo "</table>\n";
        }
 
if($x == 0) {
print "No images found";
}
else {
print "Unable to open directory";
}
}
?>
0
Comment
Question by:mhouldridge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
9 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 18011348
What's not working exactly?
0
 
LVL 16

Accepted Solution

by:
HackneyCab earned 1000 total points
ID: 18011719
It looks like you're echoing "</table>" in your for loop. So check your HTML output to see if </table> appears several times inside your table code. If that's what's happening, then I doubt most browsers would render the table the way you want. Move the echo "</table>" line to outside the for loop.
0
 
LVL 23

Expert Comment

by:Stacy Spear
ID: 18060314
This:

          }
          echo "</table>\n";
       }

Should be:

           }
       }
       echo "</table>\n";
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 16

Expert Comment

by:HackneyCab
ID: 18060986
I get the feeling this is going to be another thread left to the page editors to handle. (Been a week with no reply.)
0
 
LVL 23

Expert Comment

by:Stacy Spear
ID: 18061282
Wow, I didn't even notice, was just strolling through unanswered questions!

People should close the loop after all.
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 18062827
@HackneyCab
I know, it's one of the most frustrating things of EE. You try to help people and some of them do not have the decency to reply on the comments...
Anyway, for any future clean up voluteer. I think HackneyCab should get the points since he/ she pointed out the '</table> inside the loop' problem...
0
 
LVL 16

Expert Comment

by:HackneyCab
ID: 18062887
He, TeRReF, and thank you for your vote.

Now I guess it's just another case of wait twenty-odd days to see if the page editor gets here before the original poster.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question