Jump to content

[SOLVED] Image Gallery Script


complex05

Recommended Posts

hello,

I'm trying to make a basic image gallery script, where images are displayed from a while(readdir()), and each image is linked to the next image in the dir

so basically it'll be like gallery.php?image=1.jpg, then the image on this page will be linked to gallery.php?image=2.jpg

how do I tell the script what the next image in the directory is? here is my code:

[code]
<?php
if ($handle = opendir('.')) {
  while (false !== ($file = readdir($handle))) {
      if ($file != "." && $file != "..") {
          echo "<a href=gallery.php?image=???><img src=gallery/$file border=0></a>\n";
      }
  }
  closedir($handle);
}
?>
[/code]

Link to comment
Share on other sites

something to that effect maybe?
[code]
<?php
if($handle = opendir('.')){
while (false !== ($file = readdir($handle))){
  if($file != "." && $file != ".."){
  $images[]=$file;
  }
}
closedir($handle);
}

$current=$_GET[image];
if(empty($current)) $current=1;
$prev=$images[$current-1];
$image='<img src="gallery/'.$images[current].'">';
$next=$images[$current+1];
?>
[/code]
Link to comment
Share on other sites

Guest
This topic is now 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.