Current location: Hot Scripts Forums » Programming Languages » PHP » generate a photo page


generate a photo page

Reply
  #1 (permalink)  
Old 10-24-05, 11:41 PM
creepycridler's Avatar
creepycridler creepycridler is offline
Wannabe Coder
 
Join Date: Feb 2005
Location: Seatac, WA
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
generate a photo page

Say I want to make a script with a folder filled with "n" photos. I want this script to post the photos in a table like the following.

PHP Code:

<br><class = "pagetitle">2004 Rowathon</p>

<
CENTER><TABLE>
<
TR>
    <
TD><A HREF="images/2004rowathon/01.JPG"><IMG SRC="images/2004rowathon/thumbs/01.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/02.JPG"><IMG SRC="images/2004rowathon/thumbs/02.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/03.JPG"><IMG SRC="images/2004rowathon/thumbs/03.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/04.JPG"><IMG SRC="images/2004rowathon/thumbs/04.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/05.JPG"><IMG SRC="images/2004rowathon/thumbs/05.JPG" BORDER="0"</A></TD>
</
TR>
<
TR>
    <
TD><A HREF="images/2004rowathon/06.JPG"><IMG SRC="images/2004rowathon/thumbs/06.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/07.JPG"><IMG SRC="images/2004rowathon/thumbs/07.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/08.JPG"><IMG SRC="images/2004rowathon/thumbs/08.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/09.JPG"><IMG SRC="images/2004rowathon/thumbs/09.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/10.JPG"><IMG SRC="images/2004rowathon/thumbs/10.JPG" BORDER="0"</A></TD>
</
TR>
<
TR>
    <
TD><A HREF="images/2004rowathon/11.JPG"><IMG SRC="images/2004rowathon/thumbs/11.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/12.JPG"><IMG SRC="images/2004rowathon/thumbs/12.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/13.JPG"><IMG SRC="images/2004rowathon/thumbs/13.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/14.JPG"><IMG SRC="images/2004rowathon/thumbs/14.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/15.JPG"><IMG SRC="images/2004rowathon/thumbs/15.JPG" BORDER="0"</A></TD>
</
TR>
<
TR>
    <
TD><A HREF="images/2004rowathon/16.JPG"><IMG SRC="images/2004rowathon/thumbs/16.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/17.JPG"><IMG SRC="images/2004rowathon/thumbs/17.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/18.JPG"><IMG SRC="images/2004rowathon/thumbs/18.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/19.JPG"><IMG SRC="images/2004rowathon/thumbs/19.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/20.JPG"><IMG SRC="images/2004rowathon/thumbs/20.JPG" BORDER="0"</A></TD>
</
TR>
<
TR>
    <
TD><A HREF="images/2004rowathon/21.JPG"><IMG SRC="images/2004rowathon/thumbs/21.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/22.JPG"><IMG SRC="images/2004rowathon/thumbs/22.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/23.JPG"><IMG SRC="images/2004rowathon/thumbs/23.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/24.JPG"><IMG SRC="images/2004rowathon/thumbs/24.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/25.JPG"><IMG SRC="images/2004rowathon/thumbs/25.JPG" BORDER="0"</A></TD>
</
TR>
<
TR>
    <
TD><A HREF="images/2004rowathon/26.JPG"><IMG SRC="images/2004rowathon/thumbs/26.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/27.JPG"><IMG SRC="images/2004rowathon/thumbs/27.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/28.JPG"><IMG SRC="images/2004rowathon/thumbs/28.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/29.JPG"><IMG SRC="images/2004rowathon/thumbs/29.JPG" BORDER="0"</A></TD>
    <
TD><A HREF="images/2004rowathon/30.JPG"><IMG SRC="images/2004rowathon/thumbs/30.JPG" BORDER="0"</A></TD>
</
TR>
<
TR>
    <
TD><A HREF="images/2004rowathon/31.JPG"><IMG SRC="images/2004rowathon/thumbs/31.JPG" BORDER="0"</A></TD>    
</
TR>
</
TABLE></CENTER
Rather than creating one of these pages each time I want to add another set of photos, can a short script be written to post all these photos into a page? I could create a database table easily, but it seems to be a waste of time. Can a script look into a folder to see how many jpg files are there, then post them to the page? Does this make sense?

I would like to know if this is possible.
Thanks again all for all your help!
__________________
PCSI Design Inc.
Reply With Quote
  #2 (permalink)  
Old 10-25-05, 12:48 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
Some old code of mine ( with help from Nevermind from memory ). I use it quite a bit but can not seem to find a nice tidy version at the moment !

Notes:
1/ Reads a directory and displays image thumbnails in a table with links to larger versions - remove the <a href="display.php?pic='.$dirArray[$i].'" target="_self"> if not required.

2/ I have a "bodge" here for ($i=2; $i<$indexCount; $i++) to miss out the . & ..

3/ I have a version somewhere that will only sellect .jpg from the directory but can not find it at the moment.

4/ The $column=1; of the code is to start a new row after a certain amount of images defined here - if ($column==3)

You will just have to have a play around with it.

If you look back at some of my posts the fix for sellecting .jpg only and ignoring . & .. should be in there somewhere.

Anthony

PHP Code:

<table>

<?php

$myDirectory 
opendir'thumbs' );

    while(
$entryName readdir($myDirectory))
    {
    
$dirArray[]=$entryName;
    }
    
closedir($myDirectory);

  
$indexCount count($dirArray);

  echo 
"<center><h2>All images from the directory<br>Click on an image for a larger view</h2><table>";
  
$column=1;
  for (
$i=2$i<$indexCount$i++)
  {
    if (
$column==1)
  {
    echo 
"<tr>";
  }
   echo 
'<td align="center"><a href="display.php?pic='.$dirArray[$i].'" target="_self">
         <img border="0" src="thumbs/'
.$dirArray[$i].'" alt="'.$dirArray[$i].'"></a></td>';

  
$column++;
  if (
$column==3)
  {
  echo 
"</tr>";
  
$column=1;
  }
  }
?>

</table>

Last edited by Bonzo; 10-25-05 at 12:51 PM. Reason: Minor code change
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
user photo gallery and page template Ninety-Nine SE-L Script Requests 2 07-26-04 12:13 PM
generate text boxes from value in a text box on previous page Omega2 ASP 1 05-25-04 07:25 AM
page browsing problem mivec PHP 3 04-17-04 03:43 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 06:17 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.