Page 1 of 1

Making a PHP Photo Album?

Posted: Wed Feb 22, 2006 8:56 pm
by MikeJoel
I want to make an album that may have like 100 photos but only 5 are ever on the screen at once.

Something like a view box in the middle. Below that 5 thumbnails. Then a rewind and forward button on either side of the thumbnails to let the user move one photo forward or backward in the group. By clicking on a thumbnail it shows the photo in the box above (view).

My problem is I have been playing around with it and have found it isn't working.
PHP only works on page encoding so nothing is "live". I don't want to reload the page every time a user moves forward or back.

I can't use javascript since it cant read files and I was using files that contained the name of the thumbnail (full path), the path to the full photo and a caption text for each photo.

Any ideas?
I was wanting to make it small enough to fit on my front page.

Mike

Posted: Wed Feb 22, 2006 11:05 pm
by neophyte
Sure you can use Javascript. Just use PHP to get the file list and then dynamically print the JS you need to the browser.

Posted: Thu Feb 23, 2006 1:00 am
by John Cartwright
you could also use ajax -- this will avoid having to load all pictures at once, instead only have to fetch the next photo at a time

Posted: Thu Feb 23, 2006 8:42 am
by MikeJoel
So something like a loop in php that assigns all the photos in the album to javascript array?

Would this cause the page to download them? Because if you have like 100 photos at 57Kb each that would be 5.7Mb which would take a long time for a dailup user.

Mike

Posted: Thu Feb 23, 2006 8:53 am
by jayshields
I've also wondered about this before.

Pagination would be quite easy if you grabbed all the files, put them in a MySQL DB and then pulled them out as needed, but how can you paginate through files if you are just pulling them from a directory?

The only way I can think of is to loop through all the files every time and count as you go past each file and then eg. if you were on page one just do while counter <= 5, on page 2 do while counter > 5 and <= 10, surely that isn't the only way to do it though?

Posted: Thu Feb 23, 2006 8:59 am
by MikeJoel
The problem with that is that thr page has to be reloaded with every grab of a group of 5 photos. I am trying to prevent a reload. I have settled on allowing it for every album.


I did a test and found as long as the variable is not created and a "new Image()" it will not cache. Just using a normal variable to hold the string (which is the path to the photos) just acts like a string and only when placed as the image's src triggers the downloading.


Mike

Posted: Thu Feb 23, 2006 9:37 am
by jayshields
Oh, if you want to prevent the page from reloading you could use JavaScript/AJAX, or just include your little photoalbum bit in an iframe so that only that refreshes.