Somewhat Daily Image Script

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
TizMe
Forum Newbie
Posts: 3
Joined: Tue Jun 05, 2007 12:01 am

Somewhat Daily Image Script

Post by TizMe »

I want to create something very simple but, having not coded anything in a few years (limited then anyway), I'm having trouble wrapping my head around it. What I'd like is to have is a single index.php file and just upload image files (jpg and gif) into the same folder in this format:

1-06052007-000000.jpg
2-06062007-ffffff.jpg
3-06082007-ff0000.gif

Then I'd like index.php to include:
...
background: #ff0000;
...
<a href="?page=2"><img src="3-06082007-ff0000.gif" width="width" height="height" alt="June 8, 2007 - Page 3" /></a>

So... It would be something to the effect of:

opendir > only image files (jpg, gif, png) > array (reverse?)> explode highest number([0] if reverse I suppose) or "?page"> break apart "-" to array > link to the one before current, unless there isn't one then redirect to highest number


I have a lot of the elements and I've been looking over tons of functions, but I'm having trouble bringing it all together with my lack of experience.

Does this make sense?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Kind of. By the time I realized that you hadn't even got started, I tuned out. :lol:

Think about it at the first step, which would probably be the upload. Start there. In procedural programming, you have to take every step one at a time. In OOP, you have to plan the whole thing beforehand.
TizMe
Forum Newbie
Posts: 3
Joined: Tue Jun 05, 2007 12:01 am

Post by TizMe »

I'm gettin it figured out a bit... For simplicity I changed my image format to: number . date . bg . format (ie 1.060507.000000.jpg)

How do I take the arrays spit out and cherry pick the one with the highest value in $info[0] and then get the subsequent info from that particular array?

Code: Select all

<?php

$directory = ".";
$open = opendir($directory);

while (false !== ($file = readdir($open))) {
	if (preg_match("/\.(jpeg|jpg|gif|png)$/i", $file)) {

		$info = explode(".", $file);

		$page = $info[0];
		$date = $info[1];
		$bg = $info[2];
		
	}
}

?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Why not scan the directory and use the listing array as your way of ordering the image? I assume you want the highest number that relates to today's date?
TizMe
Forum Newbie
Posts: 3
Joined: Tue Jun 05, 2007 12:01 am

Post by TizMe »

Everah wrote:Why not scan the directory and use the listing array as your way of ordering the image? I assume you want the highest number that relates to today's date?
I'd like to go by the multiple page numbers ($info[0]), the date might change and go out of order.
Post Reply