Announcement

Collapse
No announcement yet.

PHP Image viewer script help needed:

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP Image viewer script help needed:

    Hi there ...

    I have a directory full of various images in GIF, JPG and PNG formats.

    I need to have a simple page that will read the directory and display the image and the filename in a simple little table, either in alphabetical order (by image name). It also needs to only display one letter of the alphabet at a time ... i.e. all images starting with the letter A with links to each other letter.

    Can someone please help?

    thanks in advance!

    Gordon

    I have this right now (it works but doesn't do a perfect job when it comes to sorting the images by name and I have to hard code all the links to each individual letter)

    Code:
    <?
    $alpha = $_GET['alpha'];
    if (!$alpha) {
    	$alpha = 'a';
    }
    $dir	=	'.';
    $fd	=	opendir('.');
    $x	=	0;
    
    echo	"<h4><a href=\"index.php?alpha=a\">A</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=b\">B</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=c\">C</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=d\">D</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=e\">E</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=f\">F</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=g\">G</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=h\">H</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=i\">I</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=j\">J</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=k\">K</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=l\">L</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=m\">M</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=n\">N</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=o\">O</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=p\">P</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=q\">Q</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=r\">R</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=s\">S</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=t\">T</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=u\">U</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=v\">V</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=w\">W</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=x\">X</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=y\">Y</a>";
    echo	"&nbsp;&nbsp;&nbsp;<a href=\"index.php?alpha=z\">Z</a></h4>";
    echo	"<table cellpadding=1 cellspacing=0 bgcolor=#5F7ABC border=0>";
    	echo	"<tr>";
    	echo	"<td>";
    	echo	"<table cellpadding=5 cellspacing=1 border=0>";
    		while (($part = @readdir($fd)) == true) {  
    			clearstatcache();
    			if ( eregi("(gif|jpg|png|jpeg)$",$part) ) {
    				if (substr($part,0,1) == $alpha) {
    					$x++;
    					echo	"<tr><td align=center valign=middle bgcolor=#FFFFFF>$x</td><td bgcolor=#FFFFFF><img src=$part align=absmiddle></td><td bgcolor=#FFFFFF>$part</td></tr>";
    				}
    			}
    		}
    	echo	"</table>";
    	echo	"</td>";
    	echo	"</tr>";
    echo	"</table>";
    ?>
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X