Jump to content

Archived

This topic is now archived and is closed to further replies.

SatanCow

Page count script

Recommended Posts

I'm a total n00b with PHP, I need a script that will count the number of .jpg files in a directory and re turn the number as well as the number of the current .jpg being viewed. I have no idea where to start writing this script. Just need something that will return a value on the page something like [b][ Page 9 of 45 ][/b] where it can dynamicly get the number of the current page and total page from what ever directory it's in.

Any ideas how I can do this? Maybe a starting point for writing this script.

Thanks
Andy

Share this post


Link to post
Share on other sites
Here's your starter.
[code]<?php
foreach (glob("*.jpg") as $filename) {
    $file[] = $filename; // array of all .jpg file names starting at $file[0]
}
?>[/code]

Share this post


Link to post
Share on other sites
Ok, for me I need to figure out what each thing is doing. I get that the second part is making an array of the files, what is that first line doing?

And a questions about arrays, is that array the total number of files, or should it be though of more as if there are 12 files the array is just the nmbers 1 through 12?

Share this post


Link to post
Share on other sites
Right on, i have it showing the ammount of files now

[code]foreach (glob("*.jpg") as $filename) {
    $file[] = $filename; // array of all .jpg file names starting at $file[0]
}
$array_count = count($file);
echo "$array_count";[/code]

The last problem is getting it to show me what image it is using out of the total images.
So if it's showing image 5 of 12 how do i get the code to know that were looking at image 5?

Share this post


Link to post
Share on other sites
Ok that's good enough, i'm going to quit while i'm ahead. This would have to somehow interact with the image gallery script. So it's good as it is.

One last thing, in the following code:
[code]echo "<center><strong>Current Folder: $folder Total of $array_count Pages</strong></center>";[/code]

I can't figure out how to change the font color of the $folder, and $array_count so they stick out more, inside the "" I was able to use lots of HTML tags but the one for font color won't work, is this possible? and how?

Share this post


Link to post
Share on other sites
The FONT tag is deprecated, so you won't be able to use it for much longer. If you want to change the color of text, use the STYLE attribute within a tag with the value "color: #FF0000;" or whatever you prefer.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.