Jump to content


Photo

Page count script


  • Please log in to reply
5 replies to this topic

#1 SatanCow

SatanCow
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 May 2006 - 11:52 PM

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 [ Page 9 of 45 ] 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

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 May 2006 - 12:09 AM

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

Legend has it that reading the manual never killed anyone.
My site

#3 SatanCow

SatanCow
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 May 2006 - 12:28 AM

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?

#4 SatanCow

SatanCow
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 May 2006 - 12:51 AM

Right on, i have it showing the ammount of files now

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

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?

#5 SatanCow

SatanCow
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 May 2006 - 01:09 AM

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:
echo "<center><strong>Current Folder: $folder Total of $array_count Pages</strong></center>";

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?

#6 Naimoigiant

Naimoigiant
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 23 May 2006 - 01:20 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users