Jump to content

Archived

This topic is now archived and is closed to further replies.

ShiVer

Photo Gallery

Recommended Posts

Okay, I'm creating a photo gallery, here's how I would like it to work:

The user updating the gallery simply connects to the FTP and uploads a folder with all the images in it. The folder name must be what they want the title of the album to be. And the first image in the folder alphabetically must be the image that they want to be the preview. Everyone follow? Good...

Well, I have a loop that reads the "Albums" directory which is the one they drop they're folder into. It finds all the folders in that folder and prints them with the Folder names as titles. I also have a loop that reads all the images in each individual albums and displays the image for that "Preview". The only problem is I don't know how to make so that it Only reads the FIRST image of the album for the preview rather than pulling every image and showing the Album folders repeatedly for each image. I'll leave my code for those you understand, any help would be great, you could modify my existing or write a better way. Thanks to anyone to helps in advance. If you have any questions feel free to ask, thanks,

- Ryan

[code]<?php
$od = opendir("albums");
while($dir = readdir($od)) {
if($dir[0] == '.') {
continue;
}
$nd = opendir("albums/".$dir);
while($img = readdir($nd)) {
if($img[0] == '.') {
continue;
}
echo '
<table cellpadding="2" cellspacing="1" border="0">
  <tr>
<td>'.$dir.'</td>
  </tr>
  <tr>
<td><a href="index.php"><img src="albums/'.$dir.'/'.$img.'" width="100" height="100" border="0" /></a></td>
  </tr>
</table>
';
}
}
?>[/code]

Share this post


Link to post
Share on other sites
I don't completly understand you code, but noticed that you are skipping the '.' dir. Should you be skipping the '..' dir also?

Share this post


Link to post
Share on other sites
That's observant but no actually, $img[0] simply contains the first character of each value... so the first character of . and .. matches, therefore it doesn't show.

Share this post


Link to post
Share on other sites
$dir="directoryname/";
$dr=opendir($dir); // correct method for windows.

closedir($dir);// correct way to close directory.

example ok

<?php
$dir = "/etc/php5/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
  if ($dh = opendir($dir)) {
      while (($file = readdir($dh)) !== false) {
          echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
      }
      closedir($dh);
  }
}
?>

Share this post


Link to post
Share on other sites
I still can't seem to figure this out, I've a number of different things, and each has it's own unique problem. Any ideas from anyone?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.