Jump to content

Making a php gallery.


dt_gry

Recommended Posts

I found this code online and would like to know how to alter it to suite my needs. I am need to know how to get the big versions location to be the top, and the small versions to be the subfolder. Any help would be greatly appreciated as I am trying to learn PHP.

 

<?php

$images = "image_gallery/"; # Location of small versions
$big    = "big/"; # Location of big versions (assumed to be a subdir of above)
$cols   = 2; # Number of columns to display

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="2"><hr /></td></tr><tr>';
  echo '<td align="center"><a href="' . $images . $big . $file . '"><img src="' . $images . $file . '" /></a></td>';
  $colCtr++;
}

echo '</table>' . "\r\n";

?> 

 

Thanks

dt_gry

Link to comment
https://forums.phpfreaks.com/topic/126370-making-a-php-gallery/
Share on other sites

If I am understanding you right.. you want the Larger images in the main directory, and the little ones in the sub directory...

 

if thats the case then it looks to be a settlement of symantics.. rather then upload the big files into the "big/" directory.. upload them into the "image_gallery/" directory and then apply the same concept to the small images.. and put them in the "big/" folder..

 

but I base this off of code i see here.. if theres a bigger chunk of coding missing then this may not apply..

Link to comment
https://forums.phpfreaks.com/topic/126370-making-a-php-gallery/#findComment-653507
Share on other sites

it did not work, I got the large versions posted to the page, I need to be able to do this,

 

big files dir = /big

thumb files dir = /big/thumbs

 

I have been playing around with the script but am unable to get it to work the way I need it to.

 

This is all the code, any help would be appreciated, thanks guys.

 

<?php

$images = "image_gallery/"; # Location of small versions
$big    = "big/"; # Location of big versions (assumed to be a subdir of above)
$cols   = 2; # Number of columns to display

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="2"><hr /></td></tr><tr>';
  echo '<td align="center"><a href="' . $images . $big . $file . '"><img src="' . $images . $file . '" /></a></td>';
  $colCtr++;
}

echo '</table>' . "\r\n";

?> 

 

dt_gry

Link to comment
https://forums.phpfreaks.com/topic/126370-making-a-php-gallery/#findComment-653547
Share on other sites

Archived

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

×
×
  • 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.