need help checking and selecting files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pHaZed
Forum Commoner
Posts: 28
Joined: Wed May 01, 2002 2:44 am
Location: Sydney -AU

need help checking and selecting files

Post by pHaZed »

I want to have an image gallery, Nothing special.. except I want to make all the image file names like so img_11-05.gif img_12-05.jpg etc
Where 11 is the date and 05 the month...
I want to display a latest submissions on the gallery index.
Which i was thinking i might need a while loop to gather all in last 5 days...?

Code: Select all

$num= "1";
while($num <= 5)
&#123;
    echo "<img src="img...
this is were i get stuck.. how do i get it to display the all the image submitted within the last week...
Any help would be great.
pozytron
Forum Newbie
Posts: 12
Joined: Fri May 03, 2002 7:14 pm
Location: Denver

Post by pozytron »

The main trouble with this is that it's extremely hard to find out what images exist, especially since you have imags of multiple formats, unless you are storing them in a textfile or database once submitted. If you are storing them in a database, it's easy. Just have all the images get uploaded into a single folder and add a TIMESTAMP field. Then, you can use a script that gathers all entries in the database past a certain date (five days ago). The sql would be something like

Code: Select all

"select * from images where date>now()+432000"
Just a suggestion, if it doesn't work, there's alternatives.

BTW, is there only gonna be one image per day? if not, wouldn't the image names be "img01_05_12.jpg"? If so, then you could use a while loop.

Code: Select all

$d=mktime();$file_types=array("jpg","gif","png"); //etc.
for($num=0; $n<5; $num++) {
 for($x=0;$x<count($file_types);$x++) { //You might use foreach() if you have PHP4
  $file="img_".date("d-m",$d).".".$file_types&#1111;$x];
  if (file_exists($file)) echo '<img src="'.$file.'">';
 }
 $d=$d-86400; //subtract a day
}
User avatar
pHaZed
Forum Commoner
Posts: 28
Joined: Wed May 01, 2002 2:44 am
Location: Sydney -AU

thanks

Post by pHaZed »

yea, i got it all working now. I decided to use a db instead. Less trouble :wink:
Post Reply