Re: Creating 'Next' & 'Previous' for PHP Photo Gallery

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Don't try to figure out the name of the photo that is next/previous.

Just do it "by number" and use http://php.net/array_slice after you do
glob.

This is a bit of a hack, as, technically, the Operating System is NOT
required to return the files in any particular order, nor does glob
document itself as returning them in order...

So, you could also throw in a 'sort' or you can just live with the
fact that it's only going to "work" by coincidence...

If the number of files in one directory is HUGE, sort may be too
expensive...

But probably not, so try it with the sort first and then see.

On Tue, July 10, 2007 9:01 am, Rahul Sitaram Johari wrote:
>
> I¹m trying to write a Photo Gallery in PHP. Everything else is pretty
> much
> worked out ­ like thumbnails, indexes, titles & all ­ the one thing
> I¹m
> stuck at is the Next & Previous links for the Photos on the main Photo
> Page.
>
> It¹s a simple program where you drop images in a folder and glob()
> picks up
> the thumbnails ­ displays them on a page ­ which are automatically
> linked to
> the Full Size Images. This is the code:
>
> <?
> $ID = $_GET['ID'];
> foreach (glob("$ID/thumbnails/*.jpg") as $key=>$value) {
> $title = rtrim(basename($value),'.jpg');
> $newtitle = preg_replace('/_/', ' ', $title);
> ?>
> <A HREF="photo.php?photo=<?php echo basename($value); ?>&title=<?php
> echo
> $newtitle; ?>&ID=<?php echo $_GET['ID']; ?>&KEY=<?php echo $key; ?>"
> TARGET="photoFrame">
> <IMG SRC="<?php echo $ID; ?>/thumbnails/<?php echo basename($value);
> ?>"></A>
> <?php echo $newtitle; ?>
> <?
> }
> ?>
>
> I know that $key holds the sequence of images that are being picked up
> by
> glob() - I¹m just trying to figure out a way to use this $key to
> generate
> the Next & Previous link. The problem is ­ everything is passed on to
> a
> separate page (photo.php) ... What I¹m thinking is determining which
> Photo
> File would be Next or Previous to the one being selected, and passing
> that
> along to the (photo.php) page. I¹m just not able to figure out how to
> pick
> out the next & previous filename and place it in the Query String.
>
> Any suggestions?
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Rahul Sitaram Johari
> CEO, Twenty Four Seventy Nine Inc.
>
> W: http://www.rahulsjohari.com
> E: sleepwalker@xxxxxxxxxxxxxxxx
>
> ³I morti non sono piu soli ... The dead are no longer lonely²
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux