Jump to content

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]
Link to comment
https://forums.phpfreaks.com/topic/13589-photo-gallery/
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);
  }
}
?>
Link to comment
https://forums.phpfreaks.com/topic/13589-photo-gallery/#findComment-52816
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.