Page 1 of 1

Somewhat Daily Image Script

Posted: Tue Jun 05, 2007 12:25 am
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?

Posted: Tue Jun 05, 2007 8:06 am
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.

Posted: Tue Jun 05, 2007 12:49 pm
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];
		
	}
}

?>

Posted: Tue Jun 05, 2007 1:18 pm
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?

Posted: Tue Jun 05, 2007 1:44 pm
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.