Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-23-2007, 12:32 PM   #1
Registered: Feb 2004
Location: US / EU
Distribution: Fedora 20
Posts: 158

Rep: Reputation: 19
PHP - Dynamically listing pictures - but only a certain # per page?

Hi! I have a motion activated webcam that takes pictures for a little country house I have. It uploads the pics to my server, sitting in a domain's www directory. I can just visit the website every day to make sure the house hasn't burned down!

Sometimes, when it's windy, there are lots of false alarms, and I get a ton of pictures. Rather than having all of them always displayed on the index page, how can I write the PHP code to show only, say, 30 pictures per page, with the "next page" option, which will then also just show 30 more on that page (and continuing like that for all the pictures)? I have searched online for some coding help, but I just couldn't seem to find instructions or code for what I was looking for.

Thank you for any help!!!

Here's what I have now (please no insults on my inefficient code! Or maybe, comments and suggestions, but not too harsh!) :



$dir = "./";
$dirden = "./den/";
$fd = opendir("$dir");
$fdden = opendir("$dirden");

echo "<hr><hr><b><u><h2>DRIVEWAY</h2></u></b>";

while($entry = readdir($fd)) {
if(eregi(".(exe|zip|jpg)$", $entry)) {
echo "<a href=\"$dir$entry\"><img src=\"$dir$entry\" border=\"0\">" .
echo "<br><br><hr><hr><b><u><h2>DEN</h2></u></b>";
while($entryden = readdir($fdden)) {
if(eregi(".(exe|zip|jpg)$", $entryden)) {
echo "<a href=\"$dirden$entryden\"><img src=\"$dirden$entryden\" border=\"0\">" .


Last edited by ziphem; 06-23-2007 at 12:35 PM.
Old 06-24-2007, 05:52 AM   #2
Registered: Aug 2005
Posts: 330

Rep: Reputation: 32
Replace the while with a for. And do it this way.

At the beginning get the offset.
PHP Code:

Don't use readdir, use scandir

This function returns an array of filenames.

PHP Code:


//do stuff,
echo($filenames[$i]."<br>"); //or whatever you want to do

And then, a link to the next page.

PHP Code:

"<a href='".$_SERVER['PHP_SELF']."?start=$start_at'>Next</a>"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Create and edit TAR archives dynamically with PHP and PEAR LXer Syndicated Linux News 0 02-23-2007 09:31 PM
Sendmail & PHP vs. Grey Listing BlandoCal Linux - Software 0 03-25-2006 07:12 PM
Apache/PHP Question on adding modules dynamically nyheat Linux - Software 3 03-15-2006 12:08 AM
php page can't display but download as php file? taiwf Linux - Software 2 03-07-2006 05:57 PM
php dynamically create transparent png j-ray Programming 2 08-29-2004 08:41 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:44 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration