...

View Full Version : Web Image Gallery Help



thesavior
08-19-2005, 09:25 PM
I would like a code that i can stick into my webpage, and it will take every image from a directory and automatically stick them into a page.

So lets say my directory includes:

ab.jpg
rig.gif
haha.png
dude.jpg
mwahaha.jpeg

it will transfer them into a page with source like this:

<img src="directory/ab.jpg" alt="">
<img src="directory/rig.gif" alt="">
<img src="directory/haha.png" alt="">
<img src="directory/dude.jpg" alt="">
<img src="directory/mwahaha.jpeg" alt="">

Here is the specific directory:
http://www.lonelylizard.com/~eli/files/gallery/

Also if in that directory i move some of the images into another subdirectory, lets say:

http://www.lonelylizard.com/~eli/files/gallery/sigs/
then i have like 20 images in there, it will stick them into a certain page. This needs to add them when i add the images to the server.

I am willing to use any language. If someone can code this for me and give me the code that would be awsome.

mark87
08-20-2005, 02:14 AM
This should work, haven't tested though (in PHP), you may need to play around with the name of the directory to get it to work properly.


<?php

$imgdir = './files/gallery/';
$allowed_types = array('png','jpg','jpeg','gif');

$dimg = opendir($imgdir);
while($imgfile = readdir($dimg))
{
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
{
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}

$totimg = count($a_img);

for($x=0; $x < $totimg; $x++)
{
echo '<img src="'.$a_img[$x].'" alt=""><br>';
}

?>

thesavior
08-21-2005, 01:47 AM
how do use this? i haven't use php before?

thesavior
08-21-2005, 02:23 AM
im getting this error:

http://www.lonelylizard.com/~eli/gallery.php

thesavior
08-21-2005, 09:56 PM
*bump*

thesavior
08-22-2005, 07:24 PM
*bump*

Tristan Gray
08-22-2005, 07:41 PM
Did you change the value of $imgdir or whatever to what it actually is on your server?

If so... make this:

echo '<img src="'.$a_img[$x].'" alt=""><br>';

into this:

echo '<img src=".$imgdir.'$a_img[$x].'" alt=""><br>';

Make sure $imgdir is initialized near the top of the screen as 'public_ftp/images/' or whatever your image directory is. Try that, haven't tested but I think that should be it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum